//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字段,由系统自动分配。