gpt4 book ai didi

php - fatal error : Call to a member function fetch_assoc() on a non-object

转载 作者:行者123 更新时间:2023-11-28 23:32:04 24 4
gpt4 key购买 nike

如何修复此错误?这是我的代码。

$stmt = $this->conn->prepare("SELECT ngno, email, encrypted_password, name, user_type FROM `guide` WHERE email = ?");

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

if ($stmt->execute()) {
$user = $stmt->bind_result($ngno, $email, $encrypted_password, $name, $user_type)->fetch_assoc();
$stmt->close();

我正在使用远程 SQL 数据库。我也在我的本地主机上试过这个。但是后来我得到错误, fatal error 调用 bool 值上的成员函数 fetch_assoc()

此代码使用 get_result 而不是 bind_result。但我需要使用 bind_result。

我已将代码更改为以下内容,

$stmt = $this->conn->prepare("SELECT ngno, email, encrypted_password, name, user_type FROM `guide` WHERE email = ?");

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

if ($stmt->execute()) {
$stmt->bind_result($ngno, $email, $encrypted_password, $name, $user_type);
$user = $stmt->fetch_assoc();
$stmt->close();

if($encrypted_password == $password){
return $user;
}
} else {
return NULL;
}

我现在收到这个错误。

Fatal error: Call to undefined method mysqli_stmt:: fetch_assoc()

我的查询失败了吗?

最佳答案

bind_result() 不返回对象而是状态。这意味着它不能链接到该对象的另一个方法调用。您需要分两行执行。

参见 bind_result manual page了解详情。

关于php - fatal error : Call to a member function fetch_assoc() on a non-object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37044924/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com