I've got a database with some temperature data and date. To plot the data I need to convert the datetime into ISO8601. I found the command to SELECT the correct data and transform them :
SELECT DATE_FORMAT(`datelog`, '%Y-%m-%dT%TZ') AS date_formatted FROM `tempo` ORDER BY id ASC
In phpmyadmin the data show correctly but when I run my php script with the same command it show me the data as they are stored in the DB (e.g: {"datelog":"2016-12-18 11:54:11","donnee":"16.937"}). How can I change that ?
<?php
//setting header to json
header('Content-Type: application/json');
//database
define('DB_HOST', '127.0.0.1');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '******');
define('DB_NAME', 'tempo');
//get connection
$mysqli = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
if(!$mysqli){
die("Connection failed: " . $mysqli->error);
}
//query to get data from the table
$query = "SELECT DATE_FORMAT(`datelog`, \'%Y-%m-%dT%TZ\') AS date_formatted\n" . "FROM `tempo`\n" . "ORDER BY id ASC ";
//execute query
$result = $mysqli->query($query);
//loop through the returned data
$data = array();
foreach ($result as $row) {
$data[] = $row;
}
//free memory associated with result
$result->close();
//close connection
$mysqli->close();
//now print the data
print json_encode($data);