php导出excel 大数据 时候需要注意的问题

 /**
     * 构造函数
     */
    function __construct(){
        parent::__construct();
        $this->check_page();
        $this->control   = 'admin-2016-yyyl3';
        $this->arr_table = array(
            1 => 'yyyl_order'
        );
       load_config('admin/onload');
        load_model('admin/common');
        $this->model = new CommonModel('dmz_act_2016');
    }




//导出excel

    public function saveCSV(){
        header("Content-type:text/html;charset=utf-8");
        ini_set('display_errors', 'Off');
         ini_set('max_execution_time', '3000');                                        // 就是这里需要手动改变下php.ini中的运存的大小和超时时间的长短
         ini_set('memory_limit', '1024M');

        error_reporting(0);
        $t = (int) $_GET['t'];
        if($t == 3){
            $con = mysql_connect("10.21.2.192", "game", "game");
            mysql_select_db("dmz_act_basic_2016", $con);
            $sql = "set names utf8";
            mysql_query($sql);
            $search_where = " select * from yyyl_order";
            $ret_mysql    = mysql_query($search_where);
            $ret          = array();
            while($row = mysql_fetch_array($ret_mysql)){
                $arr_item             = array();
                $arr_item['account']  = $row['account'];
                $arr_item['uin']      = $row["uin"];
                $arr_item['zone_id']  = $row['zone_id'];
                $arr_item['username'] = $row['username'];
                $arr_item['age']      = $row['age'];
                $arr_item['sex']      = $row['sex'];
                $arr_item['email']    = $row['email'];
                $arr_item['phone']    = $row['phone'];
                $arr_item['qq']       = $row['qq'];
                $arr_item['model']    = $row['model'];
                $ret[]                = $arr_item;
                //var_dump("ddd");
            }
            $header = array(
                'account'  => '账号',
                "uin"      => "UIN",
                'zone_id'  => "大区ID",
                "username" => "昵称",
                "age"      => "年龄",
                "sex"      => "性别",
                "email"    => "邮箱",
                "phone"    => "手机号",
                'qq'       => 'QQ',
                'model'    => '机型'
            );
            $data   = array_merge($headers = array($header), $ret);
            load_library('php-excel');         //  加载phpexcel库
            $xls = new Excel_XML('UTF-8', false, '预约有礼' . $t);
            $xls->addArray($data);
            ob_flush();
            flush();
            $xls->generateXML('jzsn-' . date('YmdHis'));
            exit();
        }
        $where   = "where table_name=yyyl_order";
        $rows    = $this->model->get_list('Information_schema.columns', $where, 'column_name,column_comment');
        $headers = array();
        foreach($rows as $row){
            if($row['column_name'] = "prize_id"){
                $view1['fields'][$row['column_name']] = "奖品序号";
            }
            $header[] = !empty($row['column_comment']) ? $row['column_comment'] : $row['column_name'];
        }

        $where  = "";
        $fields = "*";
        if($t == 4 && isset($_GET['num'])){
            $prize_type = (int) $_GET["num"];
            $where      = "where prize_type = $prize_type";
        }
        $rows = $this->model->get_list($this->arr_table[$t], $where, $fields);
        $data = array_merge($headers = array($header), $rows);
        load_library('php-excel');
        $xls = new Excel_XML('UTF-8', false, '预约有礼' . $t);
        $xls->addArray($data);
        ob_flush();
        flush();
        $xls->generateXML('jzsn-' . date('YmdHis'));
        exit();
    }
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值