致命错误:在system / library / user.php中调用null上的成员函数query()

时间:2017-07-14 05:46:55

标签: php

 public function login($username, $password) {

        $user_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "user WHERE username = '" . $this->db->escape($username) . "' AND (password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, SHA1('" . $this->db->escape($password) . "'))))) OR password = '" . $this->db->escape(md5($password)) . "') AND status = '1'");

        if ($user_query->num_rows) {
            $this->session->data['user_id'] = $user_query->row['user_id'];    
            $this->user_id = $user_query->row['user_id'];
            $this->username = $user_query->row['username'];
            $this->user_group_id = $user_query->row['user_group_id'];
            $user_group_query = $this->db->query("SELECT permission FROM " . DB_PREFIX . "user_group WHERE user_group_id = '" . (int)$user_query->row['user_group_id'] . "'");    
            $permissions = json_decode($user_group_query->row['permission'], true);    
            if (is_array($permissions)) {
                foreach ($permissions as $key => $value) {
                    $this->permission[$key] = $value;
                }
            }

            return true;
        }      
        else {
            return false;
        }
}

使用此函数时,我收到致命错误:在/system/library/user.php中调用null上的成员函数query()

1 个答案:

答案 0 :(得分:0)

错误" 在null上调用成员函数query()"清楚地表明您没有将 db 变量初始化为mysql连接,或者由于凭证无效而失败。

确保首先在构造函数中初始化它。