my json result from the mysqlquery in the php-file looks something like this: [{"ID":1,"comment":"Hello"},{"ID":2,"comment":"SecondHello"}]
For my purpose I need the IDs also as a String.
I cannot/do not want to change the datatype in the database.
What do I have to change in my php file or in the Sql query to get the ID as a String.
<?php
$host = '';
$db = '';
$user = '';
$pass = '';
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$pdo = new PDO($dsn, $user, $pass, $opt);
$sql= SELECT * FROM orders
$resultArray = array();
$tempArray = array();
foreach ($pdo->query($sql) as $row) {
$tempArray = $row;
array_push($resultArray, $tempArray);
}
echo json_encode($resultArray);
?>`