** 反引号(波形符)在日期内自动添加 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
最佳答案
另一种解决方案
来自文档:
$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. This is useful if you need a compound select statement.
关于php - Codeigniter 在日期格式的 SQL 查询中自动添加反引号 (`` )/波浪号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49526520/