我有這個模型
class LoginModel extends Database
{
public function signIn($userName,$password){
return $this->select("select count(*) as o_user_exists from users where usuario = ? and password = ?");
}
}
?>
我的功能選擇
public function select($query = "" , $params = [])
{
try {
$stmt = $this->executeStatement( $query , $params );
$result = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
$stmt->close();
return $result;
} catch(Exception $e) {
throw New Exception( $e->getMessage() );
}
return false;
}
在我的控制器中,我有
$userModel = new LoginModel();
$actionSignIn = $userModel->signIn($p_userName,$p_password);
$responseData = json_encode($actionSignIn[0],true);
echo $responseData->o_user_exists;

我如何從這個回報中獲得價值?
{"o_user_exists":1}
我編輯我的代碼
$userModel = new LoginModel();
$actionSignIn = $userModel->signIn($p_userName,$p_password);
$responseData = json_decode(json_encode($actionSignIn),true);
echo $responseData['o_user_exists'];
現在你得到了未定義的索引

uj5u.com熱心網友回復:
結果你得到了一個 JSON 物件。您可以將json_decode其作為陣列訪問。
$responseArray = json_decode($response, true);
$responseArray['o_user_exists'];
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/374200.html
下一篇:獲取映射和后映射
