<?php 
    require "connectionDb.php";

$suppliers = $db->query("SELECT * FROM supplier");

$json_data=[];

while ($row = $suppliers->fetchArray()) {
    //print_r($row);
$details = [
"Id" => $row['id'],
"Name" => $row['name'],
];
//here pushing the values in to an array  
array_push($json_data,$details);  
}
$json_data_all = ["data" => $json_data];

$myfile = fopen("api/v1/Suppliers/suppliers.txt", "w+") or die("Unable to open file!");;
fwrite($myfile,json_encode($json_data_all, JSON_PRETTY_PRINT));
fclose($myfile);
 ?>