2011-08-19 44 views
5

我有这个疑问:笨活动记录,添加IF在声明 - > select()函数

$this->db->select(" 
    IF(predicts.predict_owner = votes.vote_user_id , IF(judges.judge_did_accept = 1 , True , False) , 'NotExists')" , 'user_judgement'); 

我得到语法错误的

`'NotExists'`) 

如果我直接运行在数据库内查询,它工作正常...
有什么办法可以防止CI添加符号`自动?

感谢

+0

你有什么礁作为第二个参数传递给那里? –

回答

19

您可以致电与FALSE作为最后一个参数的选择方法,这样

$this->db->select("IF(predicts.predict_owner = votes.vote_user_id , IF(judges.judge_did_accept = 1 , True , False) , 'NotExists'),'user_judgement'",false); 

这将防止CI添加`

User Guide

$ this-> db-> select()接受可选的第二个参数。如果将其设置为FALSE,则CodeIgniter不会尝试使用反引号来保护字段或表名。如果您需要复合选择语句,这很有用。

PS:我看你打电话与第二PARAM为“user_judgement”选择,我不知道什么是应该做的,这不是CI希望你使用活动记录

+0

这真的帮助我。非常感谢。 –