Vote count:
0
I have a script that works but I cannot seem to adjust or find the output file. I would like the file to go to a specific directory when generated - at the moment it saves I think as test1.csv but I cannot actually find where this file is so not 100% sure it is being generated.
So ideally it would go to a directory like /var/www/html/administration/csvs in my case
include ('/var/www/html/administration/connections/connection.php');
$query = "CALL report_c05($system_id,$entity_id, $client_idx, '$start_date', '$end_date')";
$result = $con->query($query);
if (!$result) die('Couldn\'t fetch records');
$headers = $result->fetch_fields();
foreach($headers as $header) {
$head[] = $header->name;
}
$fp = fopen('php://output', 'w');
if ($fp && $result) {
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="test1.csv"');
header('Pragma: no-cache');
header('Expires: 0');
fputcsv($fp, array_values($head));
while ($row = $result->fetch_array(MYSQLI_NUM)) {
fputcsv($fp, array_values($row));
}
die;
}
Any idea please.
A secondary issue is - this runs as a cron job - and the cron log now contains all the output for this query - not very helpful - can I do anything about this?
thanks
asked 50 secs ago
MySQLi export to csv
Aucun commentaire:
Enregistrer un commentaire