好的我正在运行查询而CodeIgniter正在给我这个错误:
错误号码:1064
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 靠近''第4行
SELECT username FROM friend_request JOIN user ON user_id = friend WHERE(朋友='8'和发件人=
我确实知道,它并没有抓住发件人,但是这个> 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;
}
我尝试将所有内容放在一行,因为我不知道输入是否会破坏任何内容,但它仍然无法解决任何问题。
答案 0 :(得分:3)
您收到错误,因为您应该在查询结果上使用num_rows
,而不是在数据库上使用$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;
}
。此外,您查询绑定是错误的。
{{1}}