我正在开发一个移动应用程序,当用户登录 php/mysql 网络服务器时,用户详细信息通过 json 存储在本地 sqlite db 中。
这工作正常。接下来,我试图从 mysql DB 中的另一个表更新第二个 sqlite 表。
对于第二个查询,返回的 json 始终为 null。(如果单独运行,查询很好)
我可以像这样运行两个查询吗?有任何想法吗 ?
谢谢。
<?php
include 'DB_Connect.php';
// get tag
if (isset($_POST['email']) && $_POST['email'] != '') {
$tag = 'login';
//json response array
$response = array();
// check for tag type
if ($tag == 'login') {
$email = $_POST['email'];
$password = $_POST['password'];
//check user exists
$qry = "SELECT uid, name, email, registration_date, updated_at FROM users WHERE email = ? AND password = ? ";
$stmt = $mysqli->prepare($qry);
$stmt->bind_param('ss', $email, $password);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($uid, $name, $email, $registration_date, $updated_at); // get variables from result.
$stmt->fetch();
if ($stmt->num_rows == 1){
// if user exists, set json values
$response["success"] = 1;
$response["uid"] = $uid;
$response["user"]["name"] = $name;
$response["user"]["email"] = $email;
$response["user"]["registration_date"] = $registration_date;
$response["user"]["updated_at"] = $updated_at;
echo json_encode($response);
$stmt->close();
if ($response["success"] = 1 ){
$qry = "SELECT device_name, device_registration_date FROM devices WHERE parent_id =?";
$stmt = $mysqli->prepare($qry);
$stmt->bind_param('s',$uid);
$stmt->store_result();
$stmt->bind_result($device_name, $device_registration_date); // get variables from result.
$stmt->fetch();
$response2["device"]["device_name"] = $device_name;
$response2["device"]["device_registration_date"] = $device_registration_date;
echo json_encode($response2);
}
else if ($tag = 'register' ... blah blah blah .....