As you can see the output of PDO prepared statement vs MySQLi statement. Now the problem is that $stmt_result->fetch_assoc() is casting the numeric fields to int and float. How can this behaviour can be turned off?
As we want to move our code to MySQLi and our API is used by mobile apps so we cannot change or cast the responce fields.
=============== Using PDO ================
$stmt = $pdo->prepare($query);
$result = $stmt->execute($params);
if( $stmt->rowCount() > 0)
{
$dataset = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
header('Content-type: application/json');
echo json_encode($dataset);
Output:
[
{
"isRegistered": "0",
"DeviceOS": "Android 8.0.0",
"isActive": "1",
"City": "Brooklyn"
}
]
=============== Using MySQLi ================
$stmt = $mysqli->stmt_init();
$stmt->prepare($query);
....
$stmt->execute();
$stmt_result = $stmt->get_result();
if( $stmt_result->num_rows > 0) {
while( $row = $stmt_result->fetch_assoc() )
$dataset[] = $row;
}
header('Content-type: application/json');
echo json_encode($dataset);
Output:
[
{
"isRegistered": 0,
"DeviceOS": "Android 8.0.0",
"isActive": 1,
"City": "Brooklyn"
}
]