Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- header('Content-Type: application/json');
- //get the data from table ‘books’
- $query = "SELECT * FROM NOMETABELLA";
- //execute the query
- $result = mysqli_query($link, $query);
- if(!$result){
- echo "Couldn't execute the query";
- die();
- }
- else{
- //creates an empty array to hold data
- $data = array();
- while($row = mysqli_fetch_assoc($result)){
- $data[]=$row;
- }
- // echo json_encode($data, JSON_PRETTY_PRINT);
- //it will create file results.json with writing mode.
- //you can read more about file handling in PHP here.
- $fp = fopen('NOMEFILE.json', 'w');
- //json_enconde($array, $options(optional) is the method to convert array into JSON
- fwrite($fp, json_encode($data, JSON_PRETTY_PRINT));
- //close the file
- fclose($fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment