CodeIgniter 模型在我的查询中插入额外的字符
CodeIgniter model insert extra characters in my query
我正在 CodeIgniter 模型中执行查询,这里是我的代码:
if($query = $this->db->select('postID, users.userID, users.userFirstName, users.userLastName, postTitle, postDescription, postHtmlContent, date_format(creationDate, "%d %b, %Y") as creationDate, date_format(updationDate, "%d %b, %Y") as updationDate, cover, postType')->from('posts, users')->where('users.userID = posts.userID and postID = 1 and postStatus = "APPROVED"')->get()){
return $query->result()[0];
}else{
return NULL;
}
执行此查询时,在 mysql 控制台上运行良好,但使用 CodeIgniter 的活动记录模式,在 date_format
部分引入了一些额外的字符。这是 CodeIgniter 显示的错误,所有额外字符在 date_format(creationDate,
"%d%b,
%Y")part
.
中清晰可见
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 'FROM (`posts`, `users`) WHERE `users`.`userID` = posts.userID and postID = 1 and' at line 2
SELECT `postID`, `users`.`userID`, `users`.`userFirstName`, `users`.`userLastName`, `postTitle`, `postDescription`, `postHtmlContent`, date_format(creationDate, `"%d` %b, `%Y")` as creationDate, date_format(updationDate, `"%d` %b, `%Y")` as updationDate, `cover`, `postType` FROM (`posts`, `users`) WHERE `users`.`userID` = posts.userID and postID = 1 and postStatus = "APPROVED"
我该如何解决这个问题,我们将不胜感激。谢谢
要删除反引号,您必须向 select 部分添加第二个可选参数 (FALSE):
$this->db->select("postID, userID, . . .", FALSE);
只需添加 false
作为 select 的第二个参数,这样 codeigniter 就不会转换格式
if($query = $this->db->select('postID, users.userID, users.userFirstName, users.userLastName, postTitle, postDescription, postHtmlContent, date_format(creationDate, "%d %b, %Y") as creationDate, date_format(updationDate, "%d %b, %Y") as updationDate, cover, postType',false)->from('posts, users')->where('users.userID = posts.userID and postID = 1 and postStatus = "APPROVED"')->get()){
return $query->result()[0];
}else{
return NULL;
}
我正在 CodeIgniter 模型中执行查询,这里是我的代码:
if($query = $this->db->select('postID, users.userID, users.userFirstName, users.userLastName, postTitle, postDescription, postHtmlContent, date_format(creationDate, "%d %b, %Y") as creationDate, date_format(updationDate, "%d %b, %Y") as updationDate, cover, postType')->from('posts, users')->where('users.userID = posts.userID and postID = 1 and postStatus = "APPROVED"')->get()){
return $query->result()[0];
}else{
return NULL;
}
执行此查询时,在 mysql 控制台上运行良好,但使用 CodeIgniter 的活动记录模式,在 date_format
部分引入了一些额外的字符。这是 CodeIgniter 显示的错误,所有额外字符在 date_format(creationDate,
"%d%b,
%Y")part
.
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 'FROM (`posts`, `users`) WHERE `users`.`userID` = posts.userID and postID = 1 and' at line 2
SELECT `postID`, `users`.`userID`, `users`.`userFirstName`, `users`.`userLastName`, `postTitle`, `postDescription`, `postHtmlContent`, date_format(creationDate, `"%d` %b, `%Y")` as creationDate, date_format(updationDate, `"%d` %b, `%Y")` as updationDate, `cover`, `postType` FROM (`posts`, `users`) WHERE `users`.`userID` = posts.userID and postID = 1 and postStatus = "APPROVED"
我该如何解决这个问题,我们将不胜感激。谢谢
要删除反引号,您必须向 select 部分添加第二个可选参数 (FALSE):
$this->db->select("postID, userID, . . .", FALSE);
只需添加 false
作为 select 的第二个参数,这样 codeigniter 就不会转换格式
if($query = $this->db->select('postID, users.userID, users.userFirstName, users.userLastName, postTitle, postDescription, postHtmlContent, date_format(creationDate, "%d %b, %Y") as creationDate, date_format(updationDate, "%d %b, %Y") as updationDate, cover, postType',false)->from('posts, users')->where('users.userID = posts.userID and postID = 1 and postStatus = "APPROVED"')->get()){
return $query->result()[0];
}else{
return NULL;
}