Here is sample code that pulls data directly from MySQL:
$mysqli = new mysqli('localhost','user','password','myDatabaseName');
$myArray = array();
if ($result = $mysqli->query("SELECT * FROM reviews")) {
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
$myArray[] = $row;
}
echo json_encode($myArray);
}
$result->close();
$mysqli->close();
The problem is that Int
values, such as "id", are being shown in my JSON as String
values instead. Example:
[{
"id": "1",
"company": "Joe's Burgers",
"rating": "Good",
"affiliate": "0"
}]
In MySQL, id is an INT
type and affiliate is a TINYINT
type. How can I fix this to have properly formatted JSON? Here is what I'm expecting:
[{
"id": 1,
"company": "Joe's Burgers",
"rating": "Good",
"affiliate": 0
}]