在codeigniter中遇到問題。我有以下查詢:加入codeigniter的Sql更新
UPDATE
tbl_print_title
INNER JOIN tbl_jp_lookups ON tbl_print_title.title_id = tbl_jp_lookups.id
SET
tbl_print_title.is_delete = 1,
tbl_jp_lookups.is_delete = 1
WHERE
tbl_print_title.id = 5
我想寫在codeigniter的查詢生成器結構中。它在phpmyadmin中工作正常。我嘗試了以下,但它不起作用。請提供建議。
$this->db->set('prt.is_delete', '!is_delete');
$this->db->set('lk.is_delete', '!is_delete');
$this->db->where('prt.id',$id);
$this->db->update(TBL_PRINT_TITLE." as prt");
$this->db->join(TBL_JP_LOOKUPS." as lk", 'prt.title_id=lk.id');
if($this->db->affected_rows() > 0) {
return 1;
} else {
return 0;
}
給出一個錯誤: 錯誤編號:1054 未知列在「字段列表」「lk.is_delete」 UPDATE'tbl_print_title'如'prt' SET'prt'.'is_delete' ='!is_delete','lk'.'is_delete' ='!is_delete'WHERE'prt'.'id' ='5' 文件名:D:/ xampp/htdocs/smartquote /system/database/DB_driver.php 行號:691 –
你會嘗試編輯答案嗎? –
生成此查詢並引發錯誤。反引號刪除可能會工作。我們可以在更新查詢中防止反引號。 UPDATE'tbl_print_title爲PRT INNER JOIN tbl_jp_lookups'爲'LK ON prt'.'title_id = lk'.'id' SET'prt'.'is_delete' = '!is_delete','lk'.'is_delete' =' !is_delete'WHERE'prt'.'id' ='2' –