PHP while循环内存错误


PHP while loop memory error

我得到这个错误:

致命错误:允许的内存大小为134217728字节耗尽(试图分配> 32字节)在路径/to/1phpquery.php>第24行

第24行

while ($r = $mysqli->query($query)) {

完整代码是:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$instr = "CCBOT";
require("dbconnect.php");
$query = 'SELECT LgSpecNet, SmSpecNet, CommNet FROM cot WHERE Ticker = "$instr" LIMIT 5';
if ($result = $mysqli->query($query)) {
$table = array();
$table['cols'] = array(
array('label' => 'Large Spec Net', 'type' => 'number'),
array('label' => 'Small Spec Net', 'type' => 'number'),
array('label' => 'Commercial Net', 'type' => 'number')
);
$rows = array();
while ($r = $mysqli->query($query)) { 
$temp = array();
$ra = $r->fetch_assoc();    
$temp[] = array('v' => (int) $ra['LgSpecNet']);
$temp[] = array('v' => (int) $ra['SmSpecNet']);
$temp[] = array('v' => (int) $ra['CommNet']);
$rows[] = array('c' => $temp);
}
$result->free();
$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;
}
$mysqli->close();
?>

你正在无休止地重新运行你的查询。把

while ($r = $mysqli->query($query))

while ($ra = $result->fetch_assoc())

并删除行:

$ra = $r->fetch_assoc();