我在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()”是如何进入的?
有人能看到吗?
答案 0 :(得分: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(...);
}
P.S:你为什么要修剪并将字符串转换成小写两次?这对我来说似乎是多余的。