我得到了这段代码,用我数据库中的数据创建了一个 JSON 文件:
<?php
$connect = mysql_connect("localhost", "root", "123", "boxr") or die("Error connecting with the host.");
$sql = mysql_query("SELECT * FROM users") or die(mysql_error());
$response = array();
$users = array();
$result = mysql_query ($sql);
while ($row = mysql_fetch_array($result)) {
$gamertag = $row['gamertag'];
$banned = $row['banned'];
$users[] = array('gamertag' => $gamertag, 'banned' => $banned);
}
$response['users'] = $users;
$fp = fopen('users.json', 'w');
fwrite($fp, json_encode($response));
fclose($fp);
?>
问题是当我运行脚本时,它显示以下内容:
No database selected
我检查了我的代码两次,但我不知道为什么它告诉我。