$sth = mysqli_query("SELECT ...");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
函数json_encode
需要PHP> = 5.2和 PHP-JSON
包-如所提到的在这里
注意 :mysql
自PHP
5.5.0起已弃用,请改用mysqli
扩展名http://php.net/manual/en/migration55.deprecated.php。