Php Codeigniter/活动记录类在()中生成空白

Php Codeigniter/活动记录类在()中生成空白,php,codeigniter,Php,Codeigniter,我在Codeigniter中有一些代码,如下所示: $this->db->select('email_account_id'); $this->db->where('TRIM(LOWER(email_account_incoming_username))',trim(strtolower($email_address))); $query = $this->db->get($this->users_db.'email_account'); 抛出此错误:

我在Codeigniter中有一些代码,如下所示:

$this->db->select('email_account_id');
$this->db->where('TRIM(LOWER(email_account_incoming_username))',trim(strtolower($email_address)));
$query = $this->db->get($this->users_db.'email_account');
抛出此错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND TRIM(LOWER(email_account_incoming_username)) = 'email@server.co.uk'' at line 3
SELECT `email_account_incoming_username`, `email_account_id` FROM (`crmuat_users`.`email_account`) WHERE `email_account_id` IN () AND TRIM(LOWER(email_account_incoming_username)) = 'email@server.co.uk'
现在我一辈子都不明白“IN()”是怎么进去的


有人能看到吗?

你一定在某处调用了
$this->db->where\u in()
方法。CodeIgniter Active Record不可能在()中生成
IN
子句,除非您告诉它这样做。在执行选择之前,请尝试查看是否意外调用了该方法。还要注意的是,由于活动记录类在生成查询时具有这种奇异性的特征,因此您可能已经在其他地方使用另一个利用活动记录类的方法调用了该方法

例如,以下内容将导致在最终查询中生成
IN()
子句

function a()
{
    ...
    $this->db->where_in();
    ...
    $this->b();
}

function b()
{
    // Produces the same error as stated in the question because the call of 
    // where_in() beforehand.
    $this->db->select(...)->where(...)->get(...);
}

附言:你为什么要修剪字符串并将其转换成小写字母两次?这对我来说似乎是多余的。

我可能只需要重新初始化该类?选择
电子邮件\u帐户\u传入的\u用户名
这不在代码中…?我理解你的意思,并同意这是问题所在,但我有办法重新初始化它或清除它的缓存吗?e、 g.可能类似于$this->db->flush_cache()?不幸的是,没有。您实际上可以将类的所有属性重置回其原始状态,因为它们的访问修饰符是公共的。然而,如果我是你,我不会那么做。因为这似乎不是一个好的做法。将其编写为公共的唯一原因(使用
var
关键字)是为了PHP4的向后兼容性(我认为)。因此,如果您这样做,代码将来可能会中断(如果团队决定使用private/protected)。类中还有一些方法可用于重置这些属性。但是,它们的访问修饰符受到保护。