[英]MySQL - CodeIgniter Fails to Interpolate Query Parameters
Ok I'm running a query and CodeIgniter is giving me this error: 好的,我正在运行查询,而CodeIgniter给我这个错误:
Error Number: 1064 错误号:1064
You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4 检查与您的MySQL服务器版本相对应的手册以获取在第4行的''附近使用的正确语法
SELECT username FROM friend_request JOIN user ON user_id = friend WHERE (friend = '8' AND sender = 从friend_request中加入用户名来选择用户名user_id =朋友在哪里(朋友='8'并且发件人=
I do realize, it's not catching the sender, HOWEVER $this->session->userdata('user_id') echos to be 4 (which is my user_id)... So how come it's not showing up as anything? 我确实意识到,它没有捕获发件人,但是$ this-> session-> userdata('user_id')回显为4(这是我的user_id)...那么为什么它没有显示为任何东西?
$this->db->query('SELECT username
FROM friend_request
JOIN user ON user_id = friend
WHERE (friend = ? AND sender = ?)
OR (friend = ? AND sender = ?)',
$user->row()->user_id,
$this->session->userdata('user_id'),
$this->session->userdata('user_id'),
$user->row()->user_id);
if($this->db->num_rows() > 0) {
$this->errors->set_error('You either have a pending request from '.ucfirst($this->db->row()->username).'
or you have already requested their friendship!');
return false;
}
I tried putting everything on one line because I didn't know if the enters would break anything, but it still didn't fix any of it. 我尝试将所有内容放在一行上,因为我不知道输入是否会破坏任何内容,但仍然无法解决任何问题。
You get an error because you should use the num_rows
on the query result, not on the database. 出现错误是因为您应该在查询结果上而不是数据库上使用num_rows
。 Also, you query binding is wrong. 此外,您查询绑定是错误的。
$query = $this->db->query(
'SELECT username
FROM friend_request
JOIN user ON user_id = friend
WHERE (friend = ? AND sender = ?)
OR (friend = ? AND sender = ?)',
array(
$user->row()->user_id,
$this->session->userdata('user_id'),
$this->session->userdata('user_id'),
$user->row()->user_id
)
);
if ($query->num_rows() > 0) {
$this->errors->set_error('You either have a pending request from '.ucfirst($this->db->row()->username).'
or you have already requested their friendship!');
return false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.