//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);
天蓬老师2017-07-31 06:34:11
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:
$data =[ ['name' => '武则天','salary' => 7000,'dept' => '市场部','sex' => '女','hiredate' =>'2017-07-30'], ['name' => '嬴政','salary' => 7000,'dept' => '市场部','sex' => '男','hiredate' =>'2017-07-30'], ['name' => '孙悟空','salary' => 7000,'dept' => '市场部','sex' => '男','hiredate' =>'2017-07-30'], ];
Please remove the id field in the example array and it will be automatically assigned by the system.