<?php
header ( "Content-type:application/vnd.ms-excel" );
header ( "Content-Disposition:filename=" . iconv ( "UTF-8", "GB18030", "mycsv" ) . ".csv" );
// 打開PHP文件句柄,php://output 表示直接輸出到浏覽器
$fp = fopen('php://output', 'a');
$sql = "select count(*) as num from ".$tab;
$result = doSqlCyan($sql);
$total_export_count = $result["num"];
$pre_count = 2000;
for ($i=0;$i<intval($total_export_count/$pre_count)+1;$i++){
$sql = "select * from ".$tab." order by id asc limit ".strval($i*$pre_count).",{$pre_count}";
DB::query("set names 'utf8'");
$export_data = DB::fetch_all($sql);
foreach ( $export_data as $item ) {
$rows = array();
foreach ( $item as $export_obj){
$rows[] = iconv('utf-8', 'gbk//IGNORE', $export_obj);
// $rows[] = $export_obj;
}
fputcsv($fp, $rows);
}
// 將已經寫到csv中的數據存儲變量銷毀,釋放內存占用
unset($export_data);
ob_flush();
flush();
}
// echo "<pre>";
// print_r($rows);die;
exit ();
?>
*