我正在开发一个使用mysql数据库存储信息的Android应用程序。当我的PHP代码中有以下功能时:
/*
* Get User details
*
*/
public function getUserDetailsEse($email)
{
$stmt = $this->conn->prepare("
SELECT u.title
, u.name
, u.surname
, s.reg_num
, s.barcode
, s.prog
, s.yos
, s.sem
, s.nat_id
, s.dob
, s.mobile
, s.email
, s.addr
, s.registad_courses
FROM `users` u
, `students` s
WHERE u.id=s.uza_id
AND s.email= ?
");
$stmt->bind_param("s", $email);
$stmt->execute();
if ($stmt->num_rows > 0) {
// user existed
echo 'Query ran but nun';
$stmt->close();
return true;
} else {
// user not existed
echo 'Query ddnt run';
$stmt->close();
return false;
}
$stmt->close();
}
我想从mysql数据库中获取这些细节,然后在我的sqlite数据库中显示它们以在应用程序内使用。然后我使用:
调用该函数$details = $db->getUserDetailsEse($email);
if ($details!=FALSE){
$response1["error"] = FALSE;
$response1["id"] = $details["id"];
$response1["details"]["title"] = $details["title"];
$response1["details"]["name"] = $details["name"];
$response1["details"]["surname"] = $details["surname"];
$response1["details"]["reg_num"] = $details["reg_num"];
$response1["details"]["barcode"] = $details["barcode"];
$response1["details"]["prog"] = $details["prog"];
$response1["details"]["yos"] = $details["yos"];
$response1["details"]["sem"] = $details["sem"];
$response1["details"]["nat_id"] = $details["nat_id"];
$response1["details"]["dob"] = $details["dob"];
$response1["details"]["mobile"] = $details["mobile"];
$response1["details"]["email"] = $details["email"];
$response1["details"]["addr"] = $details["addr"];
$response1["details"]["registad_courses"] = $details["registad_courses"];
echo json_encode($response1);
} else {
$response1["error"] = TRUE;
$response1["error_msg"] = "Failed to fetch details. Login credentials are wrong. Please try again!";
echo json_encode($response1);
}
答案 0 :(得分:1)
正如您在postman响应中看到的那样,登录凭据是错误的。 您是否在PDO上配置了连接?
如果您正在使用PDO,请在下面查看连接。
<?php
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
?>
编辑: 在我的环境上我尝试了这个
public function getUserDetailsEse($email)
{
$stmt = $this->conn->prepare("
SELECT u.title
, u.name
, u.surname
, s.reg_num
, s.barcode
, s.prog
, s.yos
, s.sem
, s.nat_id
, s.dob
, s.mobile
, s.email
, s.addr
, s.registad_courses
FROM `users` u
, `students` s
WHERE u.id=s.uza_id AND u.email = :email
");
$stmt->bindParam("email", $email);
$stmt->execute();
if ($stmt->rowCount() > 0) {
// user existed
echo 'Query ran but nun';
$stmt->closeCursor();
return true;
} else {
// user not existed
echo 'Query ddnt run';
$stmt->closeCursor();
return false;
}
$stmt->closeCursor();
}
如果仍然无法解决问题,则不在您的查询中。