问题
When i try to run query in through codeigniter active records i get error as it is adding extra ``
This is the query the codeigniter is trying to execute
SELECT `T`.`id` AS TimeSheetID, DATE_FORMAT(T.date_created, `'%M')` AS MonthName FROM (`timesheet` T)
but this is the query that i actually want to execute.
SELECT `T`.`id` AS TimeSheetID, DATE_FORMAT(T.date_created, '%M') AS MonthName FROM (`timesheet` T)
how can i escape the extra colons added by the active records..
how can i write this statement to get the query work properly.
$this->db->select("
T.id AS TimeSheetID,
DATE_FORMAT(T.date_created,'%M') AS MonthName");
回答1:
Add a second parameter FALSE
in your SELECT()
So,
$this->db->select("
T.id AS TimeSheetID,
DATE_FORMAT(T.date_created,'%M') AS MonthName", FALSE);
$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks.
Reference
来源:https://stackoverflow.com/questions/27480838/mysql-codeigniter-active-records-are-adding-extra-back-ticks-to-query