2012-02-07 2 views
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 

문제는 무엇을 할 수 있을까?

+0

쓰기 권한이 있습니까? –

+0

가능한 중복 : [mysql_fetch_ *는 매개 변수 1이 리소스가 될 것으로 예상하고, 부울 주어진 오류] (http://stackoverflow.com/questions/11674312/warning-mysql-fetch-expects-parameter-1-to-be-resource) -boolean-given-error) –

답변

2

폴더 /Applications/XAMPP/xamppfiles/htdocs/test은 Apache에서 쓸 수 없습니다. 쓰기 권한을 변경하십시오. Windows 탐색기에서 test 폴더를 마우스 오른쪽 단추로 클릭하고 "읽기 전용"의 선택을 해제하십시오.

+1

감사합니다. 완벽하게 작동합니다. – user1190466

관련 문제