php大数据导出

        set_time_limit(0);

        $filename = uniqid().".csv";
        header("Content-Disposition: attachment; filename={$filename}");

        $fp = fopen("php://output", "a");
            
        $step = 20;
        $nums = 2000;

        for ($i=0; $i < $step; $i++) {
            $start = $i * $nums;
            $sql = "select * from daochu  ORDER BY id desc limit {$start},{$nums}";
            $list = DB::select($sql);
            if(!$list) break;
            foreach ($list as $key => $value) {
                $arr = [
                    iconv("UTF-8", "GBK", $value->id),
                    iconv("UTF-8", "GBK", $value->order_number),
                    iconv("UTF-8", "GBK", $value->car_number),
                    iconv("UTF-8", "GBK", $value->pay_time),
                    iconv("UTF-8", "GBK", $value->driver_name),
                    iconv("UTF-8", "GBK", $value->mobile),
                    iconv("UTF-8", "GBK", $value->fleet_name),
                    iconv("UTF-8", "GBK", $value->num),
                    iconv("UTF-8", "GBK", $value->site_name),
                ];

                fputcsv($fp, $arr);
            }

            ob_flush();
            flush();
        }

        fclose($fp);
        die;

 

hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » php大数据导出