gpt4 book ai didi

php - 使用PHP输出JSON数据,当调用太多行时,我得到 "white screen of death"

转载 作者:行者123 更新时间:2023-11-29 23:53:09 24 4
gpt4 key购买 nike

我正在使用 PHP 文件从 MySQL 数据库输出 JSON 数据。当我只提取大约 50 行时,我的代码工作得很好,但我的数据库包含超过 12,000 行。有谁知道我如何在服务器不返回“死亡白屏”的情况下提取更多数据?哈哈。我当前的代码如下:

<?php
//Create Database connection
$db = mysql_connect("localhost","username","password");
if (!$db) {
die('Could not connect to db: ' . mysql_error());
}

//Select the Database
mysql_select_db("dbname",$db);

//Replace * in the query with the column names.
$result = mysql_query("select * from customer limit 50", $db);

//Create an array
$json_response = array();

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$row_array['customerfname'] = $row['customerfname'];
$row_array['customerlname'] = $row['customerlname'];
$row_array['customeremail'] = $row['customeremail'];
$row_array['customerphone'] = $row['customerphone'];
$row_array['customercity'] = $row['customercity'];
$row_array['customeraddress'] = $row['customeraddress'];
$row_array['lastupdate'] = $row['lastupdate'];
//push the values in the array
array_push($json_response,$row_array);
}
echo json_encode($json_response);

//Close the database connection
fclose($db);

?>

最佳答案

如果前 50 行运行良好,则问题可能出在数据上......我认为是恶意单引号或其他东西

您可以像这样使用 limit 来尝试不同的数据集。例如,如果您想检查接下来的 50 个并有限制地跳过前 50 个

$result = mysql_query("select * from customer limit 50, 50", $db);  

我认为你应该尝试以 1 到 50 、 50 到 100 为一组,然后缩小到下一个 10 并找出哪个组以及哪一行/记录出现问题,然后找到 json 编码问题的解决方案面积。

关于php - 使用PHP输出JSON数据,当调用太多行时,我得到 "white screen of death",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25511336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com