PHP Fatal error: Call to a member function bind_param() on a non-object in
PHP Fatal error: Call to a member function bind_param() on a non-object in
我在 运行 下面的代码中遇到错误,请帮助我
public function storeUser($name, $email, $password, $phone,$stream) {
$response = array();
$uuid = uniqid('', true);
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
if (!$this->isUserExisted($email)) {
$stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, phone,stream, salt, created_at) VALUES('$uuid','$name','$email',$'$encrypted_password','$phone','$stream','$salt',NOW())");
$stmt->bind_param("isssisss", $uuid,$name,$email,$encrypted_password,$phone,$stream,$salt,NOW());
$result = $stmt->execute();
$stmt->close();
if ($result) {
// User successfully inserted
$response["error"] = false;
$response["user"] = $this->getUserByEmailAndPassword($email);
}else {
$response["error"] = true;
$response["message"] = "Oops! An error occurred while registereing";
}
} else {
$response["error"] = false;
$response["user"] = $this->getUserByEmailAndPassword($email);
}
return $response;
}
错误是
PHP Fatal error: Call to a member function bind_param() on a non-object in
/var/www/html/android_login_api_test/include/DB_Functions.php on line
98
您正在准备不带占位符的查询,即:
$stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, phone,stream, salt, created_at) VALUES('$uuid','$name','$email',$'$encrypted_password','$phone','$stream','$salt',NOW())");
$stmt->bind_param("isssisss", $uuid,$name,$email,$encrypted_password,$phone,$stream,$salt,NOW());
在我看来,您复制粘贴了代码。将上面的代码替换为:
$stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, phone,stream, salt, created_at) VALUES(?,?,?,?,?,?,?,NOW())");
$stmt->bind_param("isssiss", $uuid,$name,$email,$encrypted_password,$phone,$stream,$salt);
请注意,我删除了 bind_param
函数中的最后一个参数,以及该函数第一个参数中的最后一个 's'。
$stmt
存储 prepare
函数的结果。似乎 prepare
没有 return 对象,但您试图将 $stmt
作为对象访问。
我在 运行 下面的代码中遇到错误,请帮助我
public function storeUser($name, $email, $password, $phone,$stream) {
$response = array();
$uuid = uniqid('', true);
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
if (!$this->isUserExisted($email)) {
$stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, phone,stream, salt, created_at) VALUES('$uuid','$name','$email',$'$encrypted_password','$phone','$stream','$salt',NOW())");
$stmt->bind_param("isssisss", $uuid,$name,$email,$encrypted_password,$phone,$stream,$salt,NOW());
$result = $stmt->execute();
$stmt->close();
if ($result) {
// User successfully inserted
$response["error"] = false;
$response["user"] = $this->getUserByEmailAndPassword($email);
}else {
$response["error"] = true;
$response["message"] = "Oops! An error occurred while registereing";
}
} else {
$response["error"] = false;
$response["user"] = $this->getUserByEmailAndPassword($email);
}
return $response;
}
错误是
PHP Fatal error: Call to a member function bind_param() on a non-object in /var/www/html/android_login_api_test/include/DB_Functions.php on line 98
您正在准备不带占位符的查询,即:
$stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, phone,stream, salt, created_at) VALUES('$uuid','$name','$email',$'$encrypted_password','$phone','$stream','$salt',NOW())");
$stmt->bind_param("isssisss", $uuid,$name,$email,$encrypted_password,$phone,$stream,$salt,NOW());
在我看来,您复制粘贴了代码。将上面的代码替换为:
$stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, phone,stream, salt, created_at) VALUES(?,?,?,?,?,?,?,NOW())");
$stmt->bind_param("isssiss", $uuid,$name,$email,$encrypted_password,$phone,$stream,$salt);
请注意,我删除了 bind_param
函数中的最后一个参数,以及该函数第一个参数中的最后一个 's'。
$stmt
存储 prepare
函数的结果。似乎 prepare
没有 return 对象,但您试图将 $stmt
作为对象访问。