I'm building an App with React and Mobx which gets served data as JSON from an PHP/MySQL backend. The MySQL-table until now contained only simple varchar-fields and so far it worked ok. Now I added a Date-field to the table, and now I get the error SyntaxError: Unexpected end of JSON input- Why is that?
The PHP Code looks like this:
$app->get('/api/releases', function(Request $request, Response $response) {
$sql = "SELECT * FROM albums";
try{
$db = new db();
$db = $db->connect();
$stmt = $db->query($sql);
$releases = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
echo json_encode($releases);
} catch(PDOException $e) {
echo '{"error": {"text": '.$e->getMessage().'}';
}
});
Should the Date be converted to a string first?
json_encode()on an array / object there as well.