php - Codeigniter 在日期格式的 SQL 查询中自动添加反引号 (`` )/波浪号

标签 php mysql codeigniter

** 反引号(波形符)在日期内自动添加 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/

相关文章:

Codeigniter 4 电流/有源 Controller

javascript - 一键将数据插入Mysql并显示模态 codeigniter

javascript - 如何在我的 html 上使用 getJSON

php - CakePdf 生成奇怪的代码而不是 pdf

php - Magento session /缓存行为非常奇怪

mysql - 使用 TOP 子句删除 Mysql 中的查询?

codeigniter - GET 参数的 Code Igniter 重定向问题

php - 在 Wordpress 中显示 'Posts Page' 上的特色图片

PHP实时动态计算mysql结果之和

MySQL 选择 : replace parent_id column with name