When using the saveAll method, the page shows that the insertion is successful, but when viewing it using the database, the data is not inserted* (it can be successfully inserted using save)
kevlin
2017-07-30 21:31:31
//1.实例化模型,创建模型对象
$user = new Tb_users();
//2.创建对象,采用对象方式
$data =[
['id' => 1008,'name' => '武则天','salary' => 7000,'dept' => '市场部','sex' => '女','hiredate' =>'2017-07-30'],
['id' => 1009,'name' => '嬴政','salary' => 7000,'dept' => '市场部','sex' => '男','hiredate' =>'2017-07-30'],
['id' => 1011,'name' => '孙悟空','salary' => 7000,'dept' => '市场部','sex' => '男','hiredate' =>'2017-07-30'],
];
$result = $user->saveAll($data,true);
dump($result);
Are you sure about the insert operation you performed?
If so, why do you need to give the primary key id?
If you give the primary key, the update operation will be automatically performed. If no data can be queried in the table, nothing will be done.
Please reconstruct your data to be inserted as follows:
Please remove the id field in the example array and it will be automatically assigned by the system.