基本信息 Codeigniter:3,PHP 5
我目前正在一个更新查询中进行多表更新。我的SQL如下 -
UPDATE users as a, u_basicinfos as b
SET
a.first_name = 'XYI',
b.Address = 'USA',
b.PortalURL = NULL
WHERE a.id = b.UserId AND b.InfosId = 1
以上查询绝对适用于heidisql
或phpmyadmin
sql console。
我正在尝试在codeigniter中创建active records
查询,如下所示 -
$this->db->where('a.id = b.UserId');
$this->db->where('b.Infosid', $infoid);
$tblname = 'users AS a, u_basicinfos AS b';
// may be problem with this format of two tables name
$query = $this->db->update($tblname, $data);
作为备注:我在Controller中分配了$data
数组:
$data = array (
'a.first_name' => $this->input->post('first_name'),
'b.Address' => $this->input->post('Address'),
'b.NewportalURL' => $this->input->post('PortalURL')
);
现在,我正在努力解决错误。
Table 'finalportal.users as a, u_basicinfos' doesn't exist
UPDATE `users AS a, u_basicinfos` AS `b` SET `a`.`first_name` = 'XYI',
`b`.`Address` = 'USA', `b`.`PortalURL` = NULL
我需要一些关于此的想法。让我知道我做错了什么?感谢
答案 0 :(得分:0)
尝试在查询中使用此功能
$this->db->where('b.Infosid', $infoid);
$tblname = 'users a JOIN u_basicinfos b on a.id = b.UserId';
$query = $this->db->update($tblname, $data);