繁体   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