如何使用PHP將MySQL數據庫錶轉換爲JSON數據。有沒有辦法做到這一點?如何在json中使用php轉換mysql數據庫表數據
下面是PHP代碼我使用:
<?php
$host = "emriphone.db.6420177.hostedresource.com";
$user = "emriphone";
$pass = "Light12-";
$database = "emriphone";
$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");
$sth = mysql_query("SELECT * FROM ProviderAppointmentListings");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
?>
如果向我們展示建議的json數據格式,那將會很好。一般來說@Secator是對的。 – Minras 2012-03-20 11:17:03
你會得到什麼錯誤? – greut 2012-03-20 11:53:01
@greut調用未定義的函數:json_encode() – 2012-03-20 11:59:44