1
温度データと日付のあるデータベースがあります。データをプロットするために、datetimeをISO8601に変換する必要があります。 は、私が正しいデータを選択し、それらを変換するためのコマンドが見つかりました:特定のsqlコマンドからデータを取得します。
SELECT DATE_FORMAT(`datelog`, '%Y-%m-%dT%TZ') AS date_formatted FROM `tempo` ORDER BY id ASC
はphpmyadminのでは、データが正しく表示されますが、私は同じコマンドを使用して、私のPHPスクリプトを実行したときにそれらがDBに格納されているとして、それは私のデータを表示(例:{"datelog": "2016-12-18 11:54:11"、 "donnee": "16.937"})。どうすれば変更できますか?
<?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);
を例えばこのライン – eliobou
とまだ同じ出力、何があなたの出力すべきですか? – rcf2255
これは次のようなものでなければなりません:2016-12-18T00:58:05Z – eliobou