I am trying to generate a JSON file from a mysql database by using PHP. So far, I have:
<?php
error_reporting(-1);
$result=mysql_query("SELECT * FROM wp_posts");
$i=0;
while($row=mysql_fetch_array($result)) {
$response[$i]['post_status'] = $row['post_status'];
$response[$i]['post_title']= $row['post_title'];
$data['posts'][$i] = $response[$i];
$i=$i+1;
}
$json_string = json_encode($data);
$file = 'file.json';
file_put_contents($file, $json_string);
?>
This will create the file.json file but the file only contains "null".