mysql | Codeigniter Active Records are adding extra back ticks to query

纵饮孤独 提交于 2020-01-24 12:53:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!