通过mysqloutfile直接快速导出.csv文件,适用于量级很大的导出操作
直接从中直接导出csv,给你我的,供你参考
$t=time();
$filepath= getcwd().'/';
$filename=$t.'.csv';
$where='1=1';
$sql="select
field1,
filed2,
filed3
from
db.表头表
union all
select
field1,
filed2,
filed3
from
db.数据表
where
$where into outfile '$filepath$filename' character
set gbk fields terminated by ',' optionally enclosed by '\"' escaped by '\"' lines terminated by '\\r\\n' ";";
$query = db::query($sql);
header('content-description: file transfer');
header('content-type: application/octet-stream');
header('content-disposition: attachment; filename=业务日志.csv');
header('content-transfer-encoding: binary');
header('expires: 0');
header('cache-control: must-revalidate, post-check=0, pre-check=0');
header('pragma: public');
header('content-length: ' . filesize($filepath.$filename));
readfile($filepath.$filename);
unlink($filepath.$filename);
上一篇: 关于mysql子查询中使用limit