我正在尝试在Codeigniter中进行多行更新。我得到一个错误:
A Database Error Occurred
One or more rows submitted for batch updating is missing the specified index.
我认为问题出在模型内部。我把模型函数放在下面,请帮我纠正我做错的地方。
public function updateContacts($client_id){
$data = array(
array('address' => 'My address' ,
'name' => 'My Name 2' ,
),
array('address' => 'Another address' ,
'name' => 'Another Name 2' ,
)
);
$multipleWhere = ['tbl_contact.owner_id' => $client_id, 'tbl_contact.owner_type' => '3'];
$this->db->update_batch('tbl_contact', $data, $multipleWhere);
}
第三个参数应该是官方文件中的密钥,而不是where条件
The first parameter will contain the table name, the second is an associative array of values, the third parameter is the where key.
但尝试低于
$data = array(
array('address' => 'My address' ,
'name' => 'My Name 2' ,
),
array('address' => 'Another address' ,
'name' => 'Another Name 2' ,
)
);
$this->db->where('owner_id',$client_id);
$this->db->update_batch('tbl_contact', $data, 'owner_type');