基本信息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控制台。
我正试图在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);
作为注意:我在控制器中分配了$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
我需要一些关于这个的想法。让我知道我做错了什么?由于
尝试在查询
$this->db->where('b.Infosid', $infoid);
$tblname = 'users a JOIN u_basicinfos b on a.id = b.UserId';
$query = $this->db->update($tblname, $data);