I'm working with a PHP REST API, I made this function:
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() .'}}';
}
}
When I try to echo the wines
variable, echo wines->message;
, it's working, so the problem isn't from the query.
The problem is that when I try to make a call to the API without echo, nothing shows off, not even a message saying that I have no result.