我有个问题。我有一个将数据回显到 json 对象的 php 代码。这是我的代码:
<?php
$host = "localhost"; //Your database host server
$db = "..."; //Your database name
$user = "..."; //Your database user
$pass = "..."; //Your password
$connection = mysql_connect($host, $user, $pass);
//Check to see if we can connect to the server
if(!$connection)
{
die("Database server connection failed.");
}
else
{
//Attempt to select the database
$dbconnect = mysql_select_db($db, $connection);
//Check to see if we could select the database
if(!$dbconnect)
{
die("Unable to connect to the specified database!");
}
else
{
$query = "SELECT * FROM wedstrijden";
$resultset = mysql_query($query, $connection);
$records = array();
$response = array(); //extra
//Loop through all our records and add them to our array
while($r = mysql_fetch_assoc($resultset))
{
$records[] = $r;
}
//Output the data as JSON
echo json_encode($records);
}
}
?>
这样做的结果是一个 .php 文件,它与 JSON 对象相呼应。但我想要一个显示 JSON 对象的 .json 文件(如 results.json 文件)。这可能吗?
你能帮助我吗?
提前致谢。