0

如果单击提交按钮,我在这里有一个代码可以生成一个 excel 文件。该文件填充了来自 mysql 的数据,当然也基于 mysql 查询。这里是:

<?php
require("aacfs.php");

header("Content-type: application/ms-excel");
header("Content-Disposition: attachment; filename=Reservation Summary_sortbydate.xls");
header("Pragma: no-cache");
header("Expires: 0");

$head1="Ayala Aviation Corporation";
$head2="RESERVATION SUMMARY";
$head3="For the period ___________";


$heads="$head1\n$head2\n$head3\n";

$query = "select bdate as 'Date', cliename as 'Client', grpcode as 'Group Code', bperson as 'Contact', reservno as 'Reservation No.', acode as 'Aircraft', fdate as 'Flight Date', itinerary as 'Itinerary', etd as 'ETD', eta as 'ETA', pname as 'Passengers', status as 'Status', cutoff as 'Confirmation Cut-off', adminid as 'Reserved by' from reservation order by bdate";

$result = mysql_query($query);
if($result) {
    $count = mysql_num_rows($result);
   for($i=0; $i<$count; $i++) {
   for ($i = 0; $i < mysql_num_fields($result); $i++) 
    { 
    $schema_insert_rows.=mysql_field_name($result,$i) . "\t"; 
    } 
    $schema_insert_rows.="\n"; 

        while($row = mysql_fetch_row($result)) {
            $line = '';
            foreach($row as $value) {
                if((!isset($value)) OR ($value == "")) {
                    $value = "\t";
                } else {
                    $value = str_replace('"', '""', $value);
                    $value = '"'.$value.'"'."\t";
                }
                $line .= $value;
            }
            $data .= trim($line)."\n";
        }
        $data = str_replace("\r", "", $data);
        if($data == "") {
            $data = "\n(0) Records Found!\n";
        }
    }
    print mb_convert_encoding("$heads\n$schema_insert_rows\n$data", 'UTF-16LE', 'UTF-8');
} else die(mysql_error());
?>

它执行需要很长时间,当它最终下载到我的计算机上时,该文件显示一条错误消息:“超过 60 秒的最大执行时间”。我尝试像这样设置时间限制:set_time_limit(0)但仍然需要很长时间才能下载文件,当我打开下载的文件时,文件本身再次显示另一个错误:'允许的内存大小为 134217728 字节已用尽(试图分配 133693422 字节)'

我有这个确切的代码,但是在另一个 php 文件上运行了不同的 mysql_query,所以我真的很沮丧为什么这不起作用。前几天我的工作很顺利,但是当我今天再次检查时,它显示了这个错误。我究竟做错了什么?任何帮助,将不胜感激。先感谢您!上帝保佑!

4

1 回答 1

0

您是否尝试获取 10 个数据并查看它们是否具有相同的结果或错误?我认为您尝试导出的数据有点重,这就是您遇到执行超时的原因。

用这个更新你的查询。

$query = "
select 
    bdate as 'Date', 
    cliename as 'Client', 
    grpcode as 'Group Code', 
    bperson as 'Contact', 
    reservno as 'Reservation No.', 
    acode as 'Aircraft', 
    fdate as 'Flight Date', 
    itinerary as 'Itinerary', 
    etd as 'ETD', 
    eta as 'ETA', 
    pname as 'Passengers', 
    status as 'Status', 
    cutoff as 'Confirmation Cut-off', 
    adminid as 'Reserved by' 
from 
    reservation 
group by 
    bdate 
LIMIT 10";

更新你的 php.ini

     post_max_size = 8M
     default_socket_timeout = 60
于 2012-08-17T05:52:00.527 回答