我想为联合表做更新。但是,我对单引号有疑问。
我的CI活动记录:
UPDATE `pm_requirement_assign_pic_d pm_rapd INNER JOIN pm_activity_project pm_ap ON pm_rapd`.`RECEIVED_BY =` `pm_ap`.`NIP` SET `pm_rapd`.`STATUS` = 1 WHERE `pm_ap`.`UPL_FILENAME` = 'condition_1' AND `pm_rapd`.`ID_REQUIREMENT_ASSIGN_PIC` = 'condition_2'
这是查询:
UPDATE pm_requirement_assign_pic_d pm_rapd INNER JOIN pm_activity_project pm_ap ON pm_rapd.RECEIVED_BY = pm_ap.NIP SET `pm_rapd`.`STATUS` = 1 WHERE `pm_ap`.`UPL_FILENAME` = 'condition_1' AND `pm_rapd`.`ID_REQUIREMENT_ASSIGN_PIC` = 'condition_2'
所需的正确查询应为:
0
答案 0 :(得分:1)
我确信有多种方法可以实现您想要实现的目标,但我喜欢使用CodeIgniter DB的查询绑定功能。无论何时我正在做一些不仅仅是一个简单的查询,我使用查询绑定。有关详细信息,请参阅用户指南:https://www.codeigniter.com/user_guide/database/queries.html#query-bindings
function upd_pic_hps_drtu( $i_lamp, $i_id_req )
{
$this->db->query('
UPDATE pm_requirement_assign_pic_d pm_rapd
INNER JOIN pm_activity_project pm_ap
ON pm_rapd.RECEIVED_BY = pm_ap.NIP
SET `pm_rapd`.`STATUS` = 1
WHERE `pm_ap`.`UPL_FILENAME` = ?
AND `pm_rapd`.`ID_REQUIREMENT_ASSIGN_PIC` = ?
', array( $i_lamp, $i_id_req ) );
}
注意我是如何使用您想要的查询,但用问号替换值,然后将数组中的值添加为查询方法的第二个参数。
答案 1 :(得分:0)
我不确定,但你尝试过这样的事吗
function upd_pic_hps_drtu($i_lamp,$i_id_req)
{
$this->db
->set("pm_rapd.STATUS",1)
->join("pm_activity_project pm_ap","pm_rapd.RECEIVED_BY = pm_ap.NIP", "inner")
->where("pm_ap.UPL_FILENAME", $i_lamp)
->where("pm_rapd.ID_REQUIREMENT_ASSIGN_PIC", $i_id_req)
->update("pm_requirement_assign_pic_d pm_rapd");
}
如果可行的话 - 我会这样做。
Imho查询绑定功能只应在特殊情况下使用,因为查询构建器可以简化您的查询...(除了这是一个独立于数据库的层)