主页

tp5批量更新和插入新增数据

陌上吟归雪   IP属地: 青海
0 点赞 0阅读 769

Db::startTrans(); $result = false; try { foreach ($saveArr as $key=>$value) { $query = model('calendar')->where(['store_id'=>$value['store_id']])->find(); if($query){ $result = $query->isUpdate(true)->save($value); if (false === $result) { Db::rollback(); $this->error(__('No rows were updated')); } }else{ $result = model('calendar')->data($value,true)->isUpdate(false)->save(); if (!$result) { Db::rollback(); $this->error(__('No rows were updated')); } } } // $result = $row->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); }


© 著作权归作者所有,转载或内容合作请联系作者