I have some code in Codeigniter that looks like this:
$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');
Throws this error:
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'
Now I don't for the life of me understand how the "IN()" got in there?
Anybody able to see?
You must have called the $this->db->where_in()
method somewhere. It is impossible for CodeIgniter Active Record to generate the IN()
clause unless you tell it to do so. Try to see if you called the method by accident before you do the select. Also note, that since the Active Record class has this characteristic of singularity in generating query, it is possible that you've called the method somewhere else withing another method that utilizes the Active Record class.
For example, the following will cause the IN()
clause to be generated within the final query.
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: Why are you doing trimming and converting the string into lowercase twice? It seems redundant to me.