如何从mysql php查询创建json文件
我试图将从数据库检索到的数据保存到.json中。这就是刚刚尝试过的如何从mysql php查询创建json文件,php,mysql,json,Php,Mysql,Json,我试图将从数据库检索到的数据保存到.json中。这就是刚刚尝试过的 $sql = mysql_query("SELECT `positive`,`time` FROM sentiment WHERE acctid=1"); $response = array(); $posts = array(); while($row=mysql_fetch_array($sql)) { $positive=$row['positive']; $time=$row['time']; $po
$sql = mysql_query("SELECT `positive`,`time` FROM sentiment WHERE acctid=1");
$response = array();
$posts = array();
while($row=mysql_fetch_array($sql))
{
$positive=$row['positive'];
$time=$row['time'];
$posts[] = array('positive'=> $positive, 'time'=> $time,);
}
$response['posts'] = $posts;
$fp = fopen('results.json', 'w');
fwrite($fp, json_encode($response));
fclose($fp);
我得到了以下错误:
Warning: fopen(results.json) [function.fopen]: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/test/getjson.php on line 29
Warning: fwrite() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/test/getjson.php on line 30
Warning: fclose() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/test/getjson.php on line 31
问题可能是什么?Apache无法写入文件夹
/Applications/XAMPP/xamppfiles/htdocs/test
——请更改权限,使其可以写入。在Windows资源管理器中,右键单击test
文件夹,取消选中“只读”。您是否具有写入权限?可能存在重复的