I am having an issue with getting a “Allowed memory size of … bytes exhausted” when calling a SQL query thru php. I believe the array creator is stuck in a loop, somehow.
My 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();
?>
But, if i comment out:
while($des) {
$bus = array(
'description' => $des['description'],
'price' => $des['price'],
'sku' => $des['id'],
'type' => $des['type'],
);
$jsonString = array_push($json, $bus);
}
and replace $jasonString with $des i get something like:
{"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"}
I am not looking to extend the memory size, b/c one small array should not be this big.
You need to re-assign
$desinside your loop; otherwise, you’re constantly checking the same database row. Try something like this: