jnorthard / mysql-to-json

Write a MySQL Database to JSON using PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mysql-to-json

Write a MySQL Database to JSON using PHP

<?php
//Collect the data  
  $results = mysql_query("SELECT * FROM table");  
  $rows = array();
  while($r = mysql_fetch_assoc($results)) {
    $rows[] = $r;
  }
//Write the data to results.json
  $fp = fopen('results.json', 'w');
  fwrite($fp, json_encode($rows));
  fclose($fp);
?>

About

Write a MySQL Database to JSON using PHP

License:MIT License