且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

codeigniter - 数据库:如何使用单个更新查询更新多个表

更新时间:2023-02-08 17:09:15

我发现的一个解决方案是完全删除连接并将连接条件移动到 'where' 函数中,您还需要将更新字符串更改为包括新表.

One solution I have found is to remove the join altogether and move the join condition into a 'where' function, also you will need to change the update string to include the new table.

$this->db->set('a.firstname', 'Pekka');
$this->db->set('a.lastname', 'Kuronen');
$this->db->set('b.companyname', 'Suomi Oy');
$this->db->set('b.companyaddress', 'Mannerheimtie 123, Helsinki Suomi');

$this->db->where('a.id', 1);
$this->db->where('a.id = b.id');
$this->db->update('table as a, table2 as b');