簡體   English   中英

使用PHP將MySQL列導出為CSV

[英]exporting MySQL columns to CSV by using PHP

我正在嘗試使用PHP將MySQL表的某些列導出到csv文件。 到目前為止,我已經提出了以下代碼,該代碼在/ localhost的“ tabella”文件上打印出數據。 問題是它返回一個空的csv文件。 我不明白為什么。 有什么想法嗎? 謝謝!

<?php
// create a file pointer connected to the output stream
$output = fopen('tabella', 'w');
// output the column headings
fputcsv($output, array('giorno', 'mese', 'anno', 'descrizione', 'durata'));
// fetch the data
mysql_connect('localhost', 'root', '');
mysql_select_db('ore');
$rows = mysql_query('SELECT giorno,mese,anno,descrizione,((((ora_fine*60)+(min_fine))-((ora_ini*60)+(min_ini)))/60) FROM consuntivo');
// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($rows)){
fputcsv($output, $row);
}
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename=tabella.csv');
fclose($output);
?>

將文件名更改為tabella.csv

$output = fopen('tabella.csv', 'w');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM