这是导致错误的代码片段。
public function storeUser($email, $password) {
require_once 'include/user.config.inc.php';
$uuid = uniqid('', true);
//echo $uuid;
$hash = $this->hashSSHA($password);
//echo $hash;
$encrypted_password = $hash["encrypted"]; // encrypted password
//echo $encrypted_password;
$salt = $hash["salt"]; // salt
//echo $salt;
$query = "INSERT INTO user_table (unique_id, email_id, encrypted_password, salt, created_at) VALUES ( :uuid, :email, :encrypted_password, :salt, NOW()) ";
$query_params = array(
':uuid' => $uuid,
':email' => $email,
':encrypted_password' => $encrypted_password,
':salt' => $salt
);
try {
//These two statements run the query against the database table.
$stmt = $db -> prepare($query);
$result = $stmt -> execute($query_params);
} catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error! Problem with first query!";
die(json_encode($response));
}
}
我收到一个错误:
注意:未定义变量:db
致命错误:在非对象上调用成员函数 prepare()
似乎 $query 和 $query_params 导致了问题,但我不知道为什么。对我来说似乎是对的。
这是另一段代码
if ($db->isUserExisted($email)) {
// user is already existed - error response
$response["error"] = 2;
$response["error_msg"] = "User already exist";
echo json_encode($response);
} else {
$db->storeUser($email, $password);
}