Unnecessary quotes adding on sql while executing - codeigniter

Viewed 147

while trying to do a select query I came into a situation where unnecessary quotes are injecting to it on execution. I'm working in Codeigniter. Trying to selects record which having first 4 characters same. Code is:

$calendar = $this->db->select("c.first_name as cfn, u.first_name as ufn", false)
        ->from("{$this->tables['contacts']} c")
        ->join("{$this->tables['users']} u", " SUBSTR( u.first_name , 1 , 4) = SUBSTR( c.first_name , 1 , 4) ", '')
        ->where(array('c.status' => 1, 'c.first_name !=' => ''))
        ->get()->result_array();

I'm getting an error as:

FUNCTION dbname.SUBSTR does not exist. Check the 'Function Name Parsing 
and Resolution' section in the Reference Manual

SELECT c.first_name as cfn, u.first_name as ufn FROM (`contacts` c) 
JOIN `users` u ON `SUBSTR`( `u`.`first_name` , 1 , 4) = SUBSTR( c.first_name , 1 , 4) 
 WHERE `c`.`status` = 1 AND `c`.`first_name` != ''

`SUBSTR` on query is unexciting(single quote for SUBSTR).

2 Answers
Related