Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter正在以日期格式在sql查询中自动添加反勾号(``)/tilde符号_Php_Mysql_Codeigniter - Fatal编程技术网

Php Codeigniter正在以日期格式在sql查询中自动添加反勾号(``)/tilde符号

Php Codeigniter正在以日期格式在sql查询中自动添加反勾号(``)/tilde符号,php,mysql,codeigniter,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->

**背景标记(波浪符号)将自动添加到侧边日期 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->_protect_identifiers=false; 

请注意,这将删除此查询中的所有反勾号

请在查询之前尝试此行:

$this->db->_protect_identifiers=false; 

请注意,这将删除此查询上的所有反勾号,如下所示:

在数据库配置文件
/application/config/database.php
使用默认设置向数组添加新元素

$db['default']['_protect_identifiers']= FALSE;

解决方案如下:

在数据库配置文件
/application/config/database.php
使用默认设置向数组添加新元素

$db['default']['_protect_identifiers']= FALSE;

另一种解决方案

从文档中:

$this->db->select()接受可选的第二个参数。若您将其设置为FALSE,CodeIgniter将不会尝试用反勾号保护您的字段或表名。如果需要复合select语句,这将非常有用


另一种解决方案

从文档中:

$this->db->select()接受可选的第二个参数。若您将其设置为FALSE,CodeIgniter将不会尝试用反勾号保护您的字段或表名。如果需要复合select语句,这将非常有用


这是个好主意吗?由于CI的单例模式,此设置可能会在查询期间保持不变。测试它是否在之后重置,如果没有,则在完成业务后将其设置为true。保持此状态是个好主意。这是个好主意吗?由于CI的单例模式,此设置可能会在查询期间保持不变。测试它是否在之后重置,如果没有,则在完成业务后将其设置为true。保持这个状态是个好主意。请把问题弄清楚。包括预期的行为是什么?输出是什么。你的问题越清楚,就有越多的人愿意帮忙。我投票将这个问题作为离题题来结束,因为这是一种将问题和答案放在一起的尝试,但答案包含在问题中。而且很可能是重复的。请把问题弄清楚。包括预期的行为是什么?输出是什么。你的问题越清楚,就有越多的人愿意帮忙。我投票将这个问题作为离题题来结束,因为这是一种将问题和答案放在一起的尝试,但答案包含在问题中。很可能是复制品。复制粘贴得好复制粘贴得好