欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

通过mysqloutfile直接快速导出.csv文件,适用于量级很大的导出操作

程序员文章站 2022-06-15 11:40:02
直接从中直接导出csv,给你我的,供你参考 $t=time(); $filepath= getcwd().'/'; $filename=$t.'.cs...

直接从中直接导出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);