当通过 php 调用 SQL 查询时,我遇到了“允许的内存大小为......字节耗尽”的问题。我相信数组创建者不知何故陷入了循环。
我的PHP:
<?php
function confirm_query($result_set) {
if (!$result_set) {
die("DB query fail: " . mysql_error());
}
}
$con = mysql_connect("mysql15.000webhost.com", "***_mw", "***");
if (!$con) {
die("DB connect fail: " . mysql_error());
}
$mySqlDB = "a9414387_build";
$dbSelect = mysql_select_db($mySqlDB, $con);
if (!$dbSelect) {
die("db select fail: " . mysql_error());
}
$sku = $_POST['serching'];
$query = "SELECT * FROM inventory1 WHERE id LIKE '{$sku}%'";
$result = mysql_query($query, $con);
$des = mysql_fetch_array($result);
$matches = mysql_num_rows($result);
$json = array();
if ($matches > 0) {
while($des) {
$bus = array(
'description' => $des['description'],
'price' => $des['price'],
'sku' => $des['id'],
'type' => $des['type'],
);
$jsonString = array_push($json, $bus);
}
echo json_encode($jsonString);
} else {
echo json_encode(NULL);
}
die();
?>
但是,如果我注释掉:
while($des) {
$bus = array(
'description' => $des['description'],
'price' => $des['price'],
'sku' => $des['id'],
'type' => $des['type'],
);
$jsonString = array_push($json, $bus);
}
并用 $des 替换 $jasonString 我得到类似的东西:
{"0":"4040284","id":"4040284","1":"F","active":"F","2":"T","defaults":"T","3":"aurora,superNova","model":"aurora,superNova","4":null,"defmodel":null,"5":"mboard","type":"mboard","6":"105","price":"105","7":"Intel H67 (1155) Motherboard","description":"Intel H67 (1155) Motherboard","8":"1155","socket":"1155","9":"Not available at this time.","infoDiv":"Not available at this time.","10":"IntelH67Socket1155Motherboard.jpg","image":"IntelH67Socket1155Motherboard.jpg"}
我不打算扩展内存大小,b/c 一个小数组不应该这么大。