<?php
set_time_limit(0);      // 设置超时
ini_set('memory_limit', '128M');       // 设置最大使用的内存


header("Content-type:text/csv");
header("Content-Disposition:attachment;filename=" . date('Ymd'). '.csv');
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
$out = fopen('php://output', 'w');

//$out = fopen('a.csv', 'w');
$bom = chr(0xEF).chr(0xBB).chr(0xBF);     // 防止乱码


//连接数据库
$dbhost = '47.105.110.22';
$dbuser = 'zb_kkk_gg';
$dbpwd = '3KMCC8DAhNTdLm6C';
$con = mysqli_connect($dbhost, $dbuser, $dbpwd);
if (mysqli_connect_errno()) {
   die('connect error');
}
//选择数据库
$database = 'zb_kkk_gg';
mysqli_select_db($con, $database);
//设置编码
mysqli_query($con, "set names UTF8");




// 上面整理好了对应关系
$i = 0;
do{
	$list = "select * from zywd where id > $i order by id asc limit 5000";
	//echo $list."<br>";
	$requ = mysqli_query($con,$list);
	if(!mysqli_num_rows($requ)) break;
	while($row = mysqli_fetch_assoc($requ)) {
		if($row['id'] > $i) $i = $row['id'];
		fputcsv($out, $row);
	}
}while(true);
    
fclose($out);
exit();