[英]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.