If I make a simple query using PDO like this:
$dbh = new PDO("mysql:host=localhost;dbname=nameofDb", "root", "");
$sql = "select
w.id,
w.col,
w.name,
w.row,
w.sizeX,
w.sizeY,
from
widget as w
where
w.dashboard_id= ? ";
$stmt = $dbh->prepare($sql);
$stmt->execute(array($id));
$widgets = $stmt->fetchAll(PDO::FETCH_ASSOC);
$db = null;
var_dump($widgets);
And try to dump I get this:
object(stdClass)[3]
public 'dashboard_id' => string '1' (length=1)
public 'id' => string '10' (length=2)
public 'col' => string '3' (length=1)
public 'name' => string 'ggg' (length=3)
public 'row' => string '1' (length=1)
public 'sizeX' => string '1' (length=1)
public 'sizeY' => string '1' (length=1)
All values are returned as string, but col,row, sizeX,sizeY are all numbers. The problem here is that if I try to output this object as json I will get
{"dashboard_id":"1","id":"10","col":"3","name":"myName",
"row":"1","sizeX":"1","sizeY":"1"}
with all numbers in double quotes, instead I would like to have numer without quotes.
So, there is no native way for php to json encode a query and mantain the correct format?