**反引号(波形符号)自动添加iniside日期 Codeigniter中的SQL查询格式:**
$this->db->select("DISTINCT(b.dname),DATE_FORMAT(atime,' %d %M %Y
%h:%i:%s') as at");
$this->db->join('rb b','b.list_id = al.afid','LEFT');
$this->db->from('rfal al');
$this->db->where('al.afid ='.$fileid);
$this->db->where('al.is_back',1);
$this->db->order_by('at','DESC');
$this->db->limit(5);
$query= $this->db->get();
**Will Get an error as follows**
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ':%i:%s') as accessed_time FROM (`rfal` al) LEFT JOIN at line 1
SELECT DISTINCT(b.dname), DATE_FORMAT(atime, `'` %d %M %Y %h:%i:%s')
as at FROM (`rfal` al) LEFT JOIN `rb` b ON `b`.`l_id` =
`al`.`afid` WHERE `al`.`afid` =1106 AND `al`.`is_back` = 1 ORDER BY
`at` DESC LIMIT 5
答案 0 :(得分:1)
另一种解决方案
来自文档:
$ this-> db-> select()接受可选的第二个参数。如果将其设置为FALSE,CodeIgniter将不会尝试使用反引号来保护您的字段或表名称。如果您需要复合选择语句,这非常有用。
答案 1 :(得分:0)
在查询之前尝试此行:
$this->db->_protect_identifiers=false;
请注意,这将删除此查询的所有反引号
答案 2 :(得分:0)
解决方案如下:
在数据库配置文件./application/config/database.php
中
使用默认设置向阵列添加新元素。
$db['default']['_protect_identifiers']= FALSE;