suppliersVw.php 526 B

12345678910111213141516171819202122
  1. <?php
  2. require "connectionDb.php";
  3. $suppliers = $db->query("SELECT * FROM supplier");
  4. $json_data=[];
  5. while ($row = $suppliers->fetchArray()) {
  6. //print_r($row);
  7. $details = [
  8. "Id" => $row['id'],
  9. "Name" => $row['name'],
  10. ];
  11. //here pushing the values in to an array
  12. array_push($json_data,$details);
  13. }
  14. $json_data_all = ["data" => $json_data];
  15. $myfile = fopen("api/v1/Suppliers/suppliers.txt", "w+") or die("Unable to open file!");;
  16. fwrite($myfile,json_encode($json_data_all, JSON_PRETTY_PRINT));
  17. fclose($myfile);
  18. ?>