mysql | Codeigniter活动记录正在添加额外的返回滴答查询 [英] mysql | Codeigniter Active Records are adding extra back ticks to query

查看:120
本文介绍了mysql | Codeigniter活动记录正在添加额外的返回滴答查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图通过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.

Reference

这篇关于mysql | Codeigniter活动记录正在添加额外的返回滴答查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆