So I want to export a JSON file from a MySQL database table, a php script that runs weekly and exports JSON file from a specific table.
This is sort of the thing I want to achieve:
<?php
$json_file_name = "File_export.json";
$json_file_name = str_replace(" ", "_", $json_file_name);
$con = mysqli_connect("", "", "", "");
if (mysqli_connect_errno($con)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$date_range = array(
"start" => date("Y-m-d H:i:s", strtotime("-7 days")),
"end" => date("Y-m-d H:i:s", strtotime("now")),
);
and so on
if(!empty($json_data) && count($json_data) > 1)
{
$json_file_data = "";
$fp = fopen($json_file_name, 'w');
foreach($json_data as $row)
{
$json_file_data .= implode(",", $row) . "
";
}
fwrite($fp, $json_file_data);
fclose($fp);
What is the best way to achieve the same.
Thank you :)