3
<?php
require 'dbinfo.php';
try {
$db = new PDO($dsn, $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $db->query("SELECT * FROM user_tracks");
$loc = $sth->fetchAll();
$locations = array_values($loc);
echo json_encode(array("user"=>($locations)));
} catch (Exception $e) {
echo $e->getMessage();
}
?>
獲取的代碼應該返回:JSON數據:從MySQL
{"user":[{"id":"1","Latitude":"12.9555033333","Longitude":"80.2461883333","Time":"06:32:57","Date":"2012-03-13","Speed":"0","Course":"183.92"},{...},{....}]}
當它返回:
{"user":[{"id":"1","0":"1","Latitude":"12.9555033333","1":"12.9555033333","Longitude":"80.2461883333","2":"80.2461883333","Time":"06:32:57","3":"06:32:57","Date":"2012-03-13","4":"2012-03-13","Speed":"0","5":"0","Course":"183.92","6":"183.92"},{...},{....}]}
我不確定發生了什麼......的問題在哪裏?
在此先感謝!
它的工作原理!它的另一種方式.. fetchAll(PDO :: FETCH_CLASS);謝謝您的幫助! – Karthick 2012-04-03 04:02:38
Woops,對。我的錯字。我會糾正答案。 – 2012-04-03 04:52:10