3

I'm trying to save the data retrieved from the database into a .json. This is what is just tried.

$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);

I got the following errors:

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

What could the problem be?

2

1 Answer 1

2

The folder /Applications/XAMPP/xamppfiles/htdocs/test isn't writable by Apache - change the permissions so it can write to it. In Windows Explorer, right click the test folder, and untick "Read Only".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.