我有来自教程的代码,我通过Json将用户详细信息从PHP传递到Android。但是我的DB不支持get_result()。
这就是我对结果所做的事情:
if (isset($_POST['email']) && isset($_POST['password'])) {
// receiving the post params
$email = $_POST['email'];
$password = $_POST['password'];
// get the user by email and password
$user = $db->getUserByEmailAndPassword($email, $password);
if ($user != false) {
// user is found
$response["error"] = FALSE;
$response["user"]["name"] = $user["name"];
$response["user"]["surname"] = $user["surname"];
$response["user"]["address"] = $user["address"];
$response["user"]["email"] = $user["email"];
echo json_encode($response);
} else {
// user is not found with the credentials
$response["error"] = TRUE;
$response["error_msg"] = "Login credentials are wrong. Please try again!";
echo json_encode($response);
}
} else {
// required post params is missing
$response["error"] = TRUE;
$response["error_msg"] = "Required parameters email or password is missing!";
echo json_encode($response);
}
这就是我应该发送它们的方式:
public function getUserByEmailAndPassword($email, $password) {
$stmt = $this->conn->prepare("SELECT * FROM tbl_login WHERE email = ?");
$stmt->bind_param("s", $email);
if ($stmt->execute()) {
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
// verifying user password
$salt = $user['salt'];
$encrypted_password = $user['password'];
$hash = $this->checkhashSSHA($salt, $password);
// check for password equality
if ($encrypted_password == $hash) {
// user authentication details are correct
return $user;
}
} else {
return NULL;
}
}
但是行$user = $stmt->get_result()->fetch_assoc();
在我的数据库中不起作用,所以有人可以告诉我如何更改第二个文件中的代码以便它仍然可以在第一个文件中使用吗?我已经阅读过php指南等等,但我没有设法做出任何改进。