我在调用我的php文件时遇到此错误。我想获取查询返回的行。它存储名称和姓氏等基本信息。我希望resultValue在第二个注释行后面有以下结构,但我得到一个错误:
$returnValue["name"] = "jack"
$returnValue["surname"] = "london"
我知道有类似的问题,我确定我调查了所有这些问题,但我仍然遇到同样的问题。我确定我的程序有效,因为我在服务器上运行它并返回了我预期的行。
<?php
require("Connection.php");
$userName = htmlentities($_POST['userName']);
$password = htmlentities($_POST['password']);
$conn = new mysqli(Connection::$dbhost,Connection::$dbuser,Connection::$dbpass,Connection::$dbname);
$returnValue = array();
try{
$stmt = $conn->prepare("CALL login(?,?,@res);");
//stored procedure returns a row containing user information
$stmt->bind_param('ss', $userName, $password);
$res = $stmt->execute();
$returnValue = $res->fetch_array(MYSQLI_ASSOC);//Error on this line
}catch(Exception $e){
$returnValue["result"] = 0;
}
echo json_encode($returnValue);
$conn->close();
?>