Unnecessary adding quotes to sql on execution - codeigniter

When trying to execute a select query, I got into a situation where unnecessary quotes are being typed into it during execution. I work at Codeigniter. Attempts to select an entry that has the first 4 characters. Code:

$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 am getting the error:

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` is not interesting as requested (single quote for SUBSTR).

+3


source to share


2 answers


In my case, I have to fix this problem by following these steps:



$calendar = $this->db->query("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` != ''")->result_array();
print_r($calendar);

      

+1


source


I had the same problem and solved it with



str_replace('"','',$string);

      

+1


source







All Articles