//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
你確定你執行的插入操作嗎?
如果是的話,為什麼要給出主鍵id?
如果給出主鍵,將會自動執行更新操作,如果表中查詢不到數據,將什麼都不做。
請如下方式,重新建立你的待插入資料:
$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'], ];
請去掉範例數組中的id字段,由系統自動分配。