I'm trying this for the first time, so my code comes entirely from tutorials but it just doesn't work. I run PHP 7 with JSON 1.4.0 enabled.
I can print the resulting rows if I don't use json_encode, so my connection and the query are OK.
Error reporting is active but doesn't output anything either.
If I run the php file on my server, I just get a blank page.
Here's my code:
error_reporting(-1);
try {
$conn=new PDO("mysql:host=server.com;dbname=theDB",username,password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('SELECT * FROM table');
$stmt->execute();
header('Content-type: application/json');
echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}