1
我正在编写PHP后端程序,但我的程序不工作,因为PHP不支持get_result()
和fetch_assoc()
函数。PHP get_result()和fetch_assoc()替代
我该如何重写代码,以便它们能够以与此函数相同的方式工作?
public function storeUser($userLoginID, $password) {
$uuid = uniqid('', true);
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"];
$salt = $hash["salt"];
$stmt = $this->conn->prepare("INSERT INTO hkcheung.users(unique_id,userLoginID,encrypted_password,salt,created_at) VALUES (?,?,?,?,NOW())");
$stmt->bind_param("ssss", $uuid, $userLoginID, $encrypted_password, $salt);
$result = $stmt->execute();
$stmt->close();
if ($result) {
$stmt = $this->conn->prepare("SELECT * FROM hkcheung.users WHERE userLoginID=?");
$stmt->bind_param("s", $userLoginID);
$stmt->execute();
$result = $stmt->get_result();
$users = $result->fetch_assoc();
$stmt->close();
return $users;
} else {
return false;
}
}
为什么不工作?你收到的错误是什么? –
它应该可以工作,但主机不支持get_result()函数,PHP版本不够新。主持人来自我的大学,我无法自己升级,我不得不调整我的代码来应对它。但我是新来的PHP。 –
尝试使用mysqli_fetch_assoc而不是$ result-> fetch_assoc();和mysqli_stmt_get_result($ result)而不是$ result = $ stmt-> get_result(); –