Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.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 MySQL-CodeIgniter无法插入查询参数_Php_Mysql_Codeigniter - Fatal编程技术网

Php MySQL-CodeIgniter无法插入查询参数

Php MySQL-CodeIgniter无法插入查询参数,php,mysql,codeigniter,Php,Mysql,Codeigniter,好的,我正在运行一个查询,CodeIgniter给了我以下错误: 错误号码:1064 您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 在第4行的“”附近 在用户id=friend时从friend_请求加入用户中选择用户名 其中(friend='8'和发件人= 我确实意识到,它没有捕获发送者,但是$this->session->userdata('user\u id')回显为4(这是我的user\u id)。。。 那为什么它什么都没出现呢 $this->d

好的,我正在运行一个查询,CodeIgniter给了我以下错误:

错误号码:1064

您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 在第4行的“”附近

在用户id=friend时从friend_请求加入用户中选择用户名 其中(friend='8'和发件人=

我确实意识到,它没有捕获发送者,但是$this->session->userdata('user\u id')回显为4(这是我的user\u 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;
}

我尝试将所有内容放在一行上,因为我不知道enters是否会破坏任何内容,但它仍然无法修复任何内容。

您会遇到错误,因为您应该在查询结果上使用
num\u 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;
}

出现错误是因为您应该在查询结果上使用
num\u行
,而不是在数据库上。此外,您的查询绑定错误

$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;
}

致命错误:在第351行调用H:\WD SmartWare.swstor\HALEY-HP\Source\DStable\dragon\models\user\u model.php中未定义的方法CI\u DB\u mysql\u driver::num\u rows()之前我确实尝试过!我想我应该包括在内。致命错误:调用未定义的方法CI\u DB\u mysql\u driver::num\u rows()在第351行的H:\WD SmartWare.swstor\HALEY-HP\Source\DStable\dragon\models\user\u model.php中,我在发布这篇文章之前确实尝试过这一点!我想我应该包括这一点。