0

我在 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()”是怎么进来的?

有人能看吗?

4

1 回答 1

2

您一定在$this->db->where_in()某处调用了该方法。CodeIgniter Active Record 不可能生成IN()子句,除非您告诉它这样做。在进行选择之前,请尝试查看您是否偶然调用了该方法。另请注意,由于 Active Record 类在生成查询时具有这种奇异性,因此您可能在其他地方使用另一个使用 Active Record 类的方法调用了该方法。

例如,以下将导致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(...);
}

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

于 2012-06-06T12:51:17.570 回答