【问题标题】:How to create json file from mysql php query如何从 mysql php 查询创建 json 文件
【发布时间】:2012-02-07 17:46:23
【问题描述】:

我正在尝试将从数据库检索到的数据保存到 .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']; 


$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

可能是什么问题?

【问题讨论】:

标签: php mysql json


【解决方案1】:

文件夹/Applications/XAMPP/xamppfiles/htdocs/test 不能被 Apache 写入 - 更改权限以便它可以写入。在 Windows 资源管理器中,右键单击 test 文件夹,然后取消勾选“只读”。

【讨论】:

    猜你喜欢
    • 2021-06-10
    • 2015-05-29
    • 2018-08-13
    • 2011-03-25
    • 2020-09-19
    • 1970-01-01
    • 2017-06-18
    • 1970-01-01
    • 2020-10-13
    相关资源
    最近更新 更多