我正在使用PHP REST API,我做了这个功能:
function getNotifications($request) {
require_once 'db.php';
$emp = json_decode($request->getBody());
$id = $request->getAttribute("id");
$sql = "select * FROM notifications WHERE userid= :userid";
try {
$db = getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("userid", $id);
$stmt->execute();
$wines = $stmt->fetch(PDO::FETCH_OBJ);
$db = null;
return json_encode($wines);
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
当我尝试回显wines
变量echo wines->message;
时,它正在运行,因此问题不在于查询。
问题是当我尝试在没有回声的情况下调用API时,没有任何显示,甚至没有消息说我没有结果。