2016-12-18 6 views
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); 

答えて

0

それは可能性が連結で何か:

$query = "SELECT DATE_FORMAT(`datelog`, \'%Y-%m-%dT%TZ\') AS date_formatted\n" . "FROM `tempo`\n" . "ORDER BY id ASC "; 

機能なら、これを試してみてください:

$query = "SELECT DATE_FORMAT(`datelog`, \'%Y-%m-%dT%TZ\') AS date_formatted\n . " " . FROM `tempo`\n . " " . ORDER BY id ASC . "; 
+0

を例えばこのライン – eliobou

+0

とまだ同じ出力、何があなたの出力すべきですか? – rcf2255

+0

これは次のようなものでなければなりません:2016-12-18T00:58:05Z – eliobou

関連する問題