3
我試圖將從數據庫檢索到的數據保存到.json中。這是剛剛嘗試過的。如何從MySQL php查詢創建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
還有什麼問題呢?
你有寫權限嗎? – 2012-02-07 17:52:45
[Warning:mysql_fetch_ *期望參數1是資源,布爾給定錯誤]的可能的重複(http://stackoverflow.com/questions/11674312/warning-mysql-fetch-expects-parameter-1-to-be-resource -boolean-given-error) – 2012-08-02 17:41:13