简体   繁体   English

为什么会出现“致命错误:在非对象上调用成员函数fetch_assoc()”?

[英]Why am I getting a “Fatal error: Call to a member function fetch_assoc() on a non-object”?

I'm working in this project that is an Android login app. 我正在做一个Android登录应用程序的项目。 It fetches data from an online server. 它从在线服务器获取数据。

The registration works and the database gets updated but the login does not work. 注册有效,数据库已更新,但登录无效。 We are using JSON to parse data from the server to the app. 我们正在使用JSON将数据从服务器解析到应用程序。

Here is my PHP code: 这是我的PHP代码:

public function getUserByEmailAndPassword($email, $password) {

    $stmt = $this->conn->prepare("SELECT * FROM user_info WHERE email = ?");

    $stmt->bind_param("s", $email);

    if ($stmt->execute()) {
        $user = $stmt->bind_result()->fetch_assoc();
        $stmt->close();
        return $user;
    } 
    else {
        return NULL;
    }
}

The error I'm getting is the following: 我收到的错误如下:

Fatal error: Call to a member function fetch_assoc() on a non-object.

bind_result() is not the method you want here. bind_result()不是您想要的方法。 That method (which returns a boolean, by the way) lets you assign variables to the columns returned in your query. 该方法(顺便返回一个布尔值)使您可以将变量分配给查询中返回的列。 Your query uses SELECT * , so you cannot use bind_result() . 您的查询使用SELECT * ,因此不能使用bind_result()

What you want is to use get_result() . 您要使用get_result() This requires the mysqlnd driver to be installed. 这需要安装mysqlnd驱动程序。

$user = $stmt->get_result()->fetch_assoc();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么会得到:为此递归函数在非对象上调用成员函数fetch_assoc()? - Why am I getting: Call to a member function fetch_assoc() on a non-object for this recursive function? 在 SQL 查询中出现“致命错误:在非对象上调用成员函数 fetch_assoc()” - Getting "Fatal error: Call to a member function fetch_assoc() on a non-object" on SQL query 致命错误:在非对象上调用成员函数fetch_assoc()- - Fatal error: Call to a member function fetch_assoc() on a non-object - PHP致命错误:在非对象上调用成员函数fetch_assoc() - PHP Fatal error: Call to a member function fetch_assoc() on a non-object 致命错误:在非对象上调用成员函数fetch_assoc() - Fatal error: Call to a member function fetch_assoc() on a non-object 致命错误:在非对象上调用成员函数 fetch_assoc() - Fatal error: Call to a member function fetch_assoc() on a non-object 致命错误:插入时在非对象上调用成员函数fetch_assoc() - Fatal error: Call to a member function fetch_assoc() on a non-object on insertion 致命错误:在非对象(mysqli)上调用成员函数fetch_assoc() - Fatal error: Call to a member function fetch_assoc() on a non-object (mysqli) 致命错误:将结果转换为数组时,在非对象上调用成员函数fetch_assoc() - Fatal error: Call to a member function fetch_assoc() on a non-object while converting result to array 致命错误:在非对象上调用成员函数Fetch_Assoc() - Fatal Error: Call To A Member Function Fetch_Assoc() On A Non-Object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM