【发布时间】:2017-02-23 08:19:26
【问题描述】:
我正在尝试从一个 mysql 表中获取大量数据以导出为 XLSX 文件。
我使用了 fetchAll() 函数,但我得到了
Fatal error: Out of memory
这是我的代码:
<?php
require_once 'classes/Spout/Autoloader/autoload.php';
use Box\Spout\Writer\WriterFactory;
use Box\Spout\Common\Type;
$query = "SELECT *
FROM full_report";
$header = array('DATA','STORE','FROM','TO','DATE','YEAR','MONTH','ITEM','SIZE','DEPT','SUBDEPT','DESC1','DESC2','GENDER','ATTR','VEND','SEASON','INVO#','TRANS#','QTY','MSRP','RTP','COST','T.RTP','T.COST','PAYMENT','STATUS');
$mDb->query($query);
$result = $mDb->fetchAll(); // Here where I get the error!
$fileName = "fullReport-" . date('m-d-Y-H-i-s') . ".xlsx";
$path = "_uploads/" . $fileName;
$writer = WriterFactory::create(Type::XLSX); // for XLSX files
$writer->openToFile($path); // write data to a file or to a PHP stream
$writer->openToBrowser($path); // stream data directly to the browser
$writer->addRow($header);
foreach ($result as $value)
{
unset($value['id']);
unset($value[0]);
$valuex[] = array_values($value);
}
$writer->addRows($valuex);
$writer->close();
有什么建议吗?
【问题讨论】:
-
有更多内存的服务器?或者您可以查看应用程序或 Web 服务器的内存限制,例如查看 stackoverflow.com/questions/13955914/… 并检查您的 php 限制 techpp.com/2009/07/10/how-to-fix-php-fatal-error-out-of-memory
标签: php mysql out-of-memory limit fetchall