I need exactly this, to change the .json I am generating on every change of the DB. Can anybody tell me how I can go about doing this? Also, as a side note, how can I enable utf-8 encoding in this?
This is my code right now:
$return_arr = array();
include("connect.php");
header('Content-Type: text/html; charset=utf-8');
$name = $_GET['name'];
$fetch = "SELECT * FROM {$name}";
if ($result = mysqli_query($conn,$fetch)) {
while($row = $result->fetch_assoc()) {
$myArray[] = $row;
}
}
$json = json_encode($myArray,JSON_UNESCAPED_UNICODE);
$fp = fopen('nlb.json', 'w');
fwrite($fp, $json);
fclose($fp);
$conn->close();
PS is there any way to automatically generate a php script on an interval of idk like 1 hour? That would be a nice workaround, but not very effective since my DB has over 100 entries.
Aucun commentaire:
Enregistrer un commentaire