【问题标题】:Two different table name in Codeigniter update functionCodeigniter 更新函数中有两个不同的表名
【发布时间】:2015-09-12 19:59:33
【问题描述】:

基本信息 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

上述查询绝对适用于heidisqlphpmyadmin 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);

注意:我已经在 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

我需要一些想法。让我知道我做错了什么?谢谢

【问题讨论】:

    标签: php mysql codeigniter


    【解决方案1】:

    尝试在查询中使用它

    $this->db->where('b.Infosid', $infoid);
    $tblname = 'users a JOIN u_basicinfos b on a.id = b.UserId';
    $query = $this->db->update($tblname, $data);
    

    【讨论】:

    • 试过了。没运气。我认为更新函数第一个参数中的tables name 有问题。它会以适当的方式进行。我在这里做错了,绝对。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-20
    • 2020-04-24
    • 2015-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多