Mysql
 SQL >> Database >  >> RDS >> Mysql

Esportare dati PHP MySQL in un file JSON

Puoi usare la funzione json_encode.

  1. Recupera i dati dal db e assegnali a un array
  2. Poi usa json_encode($result_array). Questo produrrà il risultato JSON. Clicca qui
  3. Usa la funzione file_put_contents per salvare il risultato JSON nel tuo file .json

Di seguito un esempio di codice:

$result = mysql_query(your sql here); $data = array(); while ($row = mysql_fetch_assoc($result)) { // Generate the output in desired format $data = array( 'cols' => .... 'rows' => .... 'p' => ... ); } $json_data = json_encode($data); file_put_contents('your_json_file.json', $json_data);