I am using PDO to output SQL results to JSON. The problem is that everything is a string, but I would like integers and booleans not to be string. Is there a way to do this?
This is what I am doing:
$db = getConnection();
$stmt = $db->query('SELECT * FROM chapters');
$results = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
echo json_encode($results);
And this is what it give me:
[{"id":"1","name":"Book1","pages":"123",active:"\u0001"}]
But I would it to output this:
[{"id":1,"name":"Book1","pages":123,active:true}]
The columns in MySQL columns are indeed ints and bits. How to I output the right types so I don't have to parse these on the client-side?