**反记号(代字号)正在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 发布于 2018-03-28 13:35:29
另一个解决方案
从文档中:
$this->db->select()接受第二个可选参数。如果您将其设置为FALSE,CodeIgniter将不会尝试使用反号保护您的字段或表名。如果您需要复合select语句,这将非常有用。
发布于 2018-03-28 13:11:32
在查询之前尝试这一行:
$this->db->_protect_identifiers=false; 请注意,这将删除此查询上的所有反引号
发布于 2018-03-28 13:24:21
解决方案如下:
在数据库配置文件./application/config/database.php中,使用默认设置向数组添加一个新元素。
$db['default']['_protect_identifiers']= FALSE;https://stackoverflow.com/questions/49526520
复制相似问题