将数据库连接信息、查询条件、标题信息替换为真实数据即可使用。
1 $item) {40 $title[$key] =iconv("UTF-8", "GBK", $item);41 }42 //将标题写到标准输出中43 fputcsv($fp, $title);44 45 for($s = 1; $s <= $step; $s++) {46 $start = ($s - 1) * $nums;47 $result = mysqli_query($con,"SELECT * FROM `test` ".$where." ORDER BY `id` LIMIT {$start},{$nums}");48 if($result) {49 while($row = mysqli_fetch_assoc($result)) {50 foreach($row as $key => $item) {51 //这里必须转码,不然会乱码52 $row[$key] = iconv("UTF-8", "GBK", $item);53 }54 fputcsv($fp, $row);55 }56 mysqli_free_result($result); //释放结果集资源57 58 //每1万条数据就刷新缓冲区59 ob_flush();60 flush();61 }62 }63 //断开连接64 mysqli_close($con);