gpt4 book ai didi

php - JsonArray 返回空值

转载 作者:行者123 更新时间:2023-11-29 03:25:52 25 4
gpt4 key购买 nike

下面是我的 php 代码:

public function getMainChatList($myPhoneNo){

$stmt = $this->conn->prepare("SELECT receiverPhoneNo,name FROM users,friend WHERE users.phoneNo=friend.receiverPhoneNo AND senderPhoneNo=? AND chatted = 'y' ORDER BY update_time DESC");
$stmt->bind_param("s", $myPhoneNo);
$stmt->execute();
$stmt->store_result();

$result = array();

while($row = $stmt->fetch()){
array_push($result,array('receiverPhoneNo'=>$row['receiverPhoneNo'],'name'=>$row['name'],));
}
//echo json_encode(array("result"=>$result));
echo json_encode($result);
echo json_last_error();
$stmt->close();
}

返回json

[{"receiverPhoneNo":null,"name":null},{"receiverPhoneNo":null,"name":null}]0

json_last_error() 返回 0。我不知道它为什么返回 null。而我直接在xampp MySQL服务器上执行sql语句。下面是结果。

result.jpg谢谢!

最佳答案

只需使用 bind_result()相反:

public function getMainChatList($myPhoneNo)
{
$stmt = $this->conn->prepare("
SELECT receiverPhoneNo, name FROM users, friend
WHERE users.phoneNo = friend.receiverPhoneNo
AND senderPhoneNo = ?
AND chatted = 'y'
ORDER BY update_time DESC
");
$stmt->bind_param('s', $myPhoneNo);
$stmt->execute();
// bind
$stmt->bind_result($receiverPhoneNo, $name);

$result = array();

while($stmt->fetch()){
$result[] = array(
'receiverPhoneNo' => $receiverPhoneNo,
'name' => $name,
);
}

echo json_encode($result);
}

关于php - JsonArray 返回空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36393454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com