mysql | Codeigniter活动记录正在添加额外的返回滴答查询 [英] mysql | Codeigniter Active Records are adding extra back ticks to query
问题描述
当我试图通过codeigniter运行查询活动记录我得到错误,因为它是添加额外``
这是codeigniter试图执行的查询
SELECT`T`.`id` AS TimeSheetID,DATE_FORMAT .date_created,`'M')`AS MonthName FROM(`timesheet`T)
是我实际想要执行的查询。
SELECT`T`.`id` AS TimeSheetID,DATE_FORMAT(T.date_created ,'%M')AS MonthName FROM(`timesheet`T)
<$>
<$> p $ p>
$ this-> db-> select(
T.id AS TimeSheetID,
DATE_FORMAT(T.date_created,'%M')AS MonthName );
添加第二个参数 FALSE $
$ this-> db-> select(
T.id AS TimeSheetID,
DATE_FORMAT(T.date_created,'% M')AS MonthName,FALSE);
$ this-> db-> select()接受可选的第二个参数。如果将其设置为FALSE,CodeIgniter将不会尝试使用反引号保护您的字段或表名。
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");
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.
这篇关于mysql | Codeigniter活动记录正在添加额外的返回滴答查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!