-
Notifications
You must be signed in to change notification settings - Fork 9
/
example.php
36 lines (23 loc) · 1.05 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
include_once "excelclass/ExcelExport.php";
$limit = 10000; //一次查询一万条记录
$filename = 'login_log';
$title = ['id'=>'ID','user_id'=>'用户id','plat'=>'渠道','username'=>'用户名','sex'=>'性别','ip'=>'用户ip','register_time'=>'注册时间'];
$filter = ['sex'=>[1=>'男', 0=>'女'], 'register_time'=>'datetime'];
$con = mysqli_connect('127.0.0.1','root','pass','dbname') or die('数据库连接不上');
$countSql = "select count(*) from user";
$count = mysqli_fetch_assoc(mysqli_query($con,$countSql));
$total = $count['count(*)'];
$excelObj = (new ExcelExport())->filename($filename)->title($title)->filter($filter);
for ($i=0; $i < ceil($total/$limit); $i++) { //分段查询
$offset = $i * $limit;
$dataSql = "select * from user limit $limit offset $offset";
$result = mysqli_query($con, $dataSql);
$data = [];
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
$res = $excelObj->excel($data, $i+1); //生成多个文件时的文件名后面会标注'($i+1)'
}
mysqli_close($con);
$excelObj->fileload();