![](/img/trans.png)
[英]Codeigniter Active Record Select statement with not so normal statements
[英]CodeIgniter active record, Add IF statement in ->select() function
我有這個問題:
$this->db->select("
IF(predicts.predict_owner = votes.vote_user_id , IF(judges.judge_did_accept = 1 , True , False) , 'NotExists' )" , 'user_judgement');
我得到語法錯誤
`'NotExists'` )
如果我直接在數據庫中運行查詢,它工作正常...
有沒有辦法阻止CI自動添加標志?
謝謝
您可以使用FALSE作為最后一個參數調用select方法,就像這樣
$this->db->select("IF(predicts.predict_owner = votes.vote_user_id , IF(judges.judge_did_accept = 1 , True , False) , 'NotExists' ),'user_judgement'",false);
這將阻止CI添加`
來自用戶指南
$ this-> db-> select()接受可選的第二個參數。 如果將其設置為FALSE,CodeIgniter將不會嘗試使用反引號來保護您的字段或表名稱。 如果您需要復合選擇語句,這非常有用。
PS:我看到你用第二個參數調用select作為“user_judgement”,我不確定應該做什么,這不是cay CI希望你使用Active Record
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.