我一直在尝试导出大量数据(执行匹配查询后)。
当我将数量限制为小到50时,效果非常好。但是一旦我从查询中删除了限制,它就会运行并显示内部服务器错误(500)。我确保服务器的最大执行时间为360000,内存限制为1600 M.预期结果数约为200K。
以下是我使用LIMIT
的代码$dbhost = 'myhost';
$dbuser = 'user';
$dbpass = 'pass';
$dbname = 'mydb';
$conn = new mysqli("$dbhost", "$dbuser", "$dbpass", "$dbname");
if ($conn->connect_errno) {
echo "Failed to connect to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error;
}
$sql = "SELECT *FROM `master_Prospects` WHERE `City` IN (SELECT DISTINCT `City` FROM `data_Footprint`) AND `State` IN (SELECT DISTINCT `State` FROM `data_Footprint`) AND `Street` IN (SELECT DISTINCT `Street` FROM `data_Footprint`) LIMIT 0, 50" ;
$query = mysqli_query($conn,$sql);
$columns_total = mysqli_num_fields($query);
$fields_data = mysqli_fetch_fields($query);
$heading_array = array();
for ($i = 0; $i < $columns_total; $i++) {
$heading = $fields_data[$i]->name;
$heading_array[$i] = $heading;
}
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen('php://output', 'w');
fputcsv($output,$heading_array);
// loop over the rows, outputting them
while ($row = mysqli_fetch_assoc($query)) fputcsv($output, $row);