如何修复运行函数时的 PHP 内存错误



我在运行PHP函数时遇到内存错误。

错误显示为...

致命错误:允许的内存大小 268435456 字节已耗尽(尝试分配 4294967296 字节(

PHP脚本是...

function getPageContent($page) {
//Open a new connection to the MySQL server
$mysqli = new mysqli('localhost','MY_USER','MY_PASS','MY_DATABASE');
$account = MY_ACCOUNT_NUMBER;
$project = 1;
if($stmt=$mysqli->prepare("SELECT content FROM pages WHERE account_id=? AND id=? LIMIT 1")){
$stmt-> bind_param("ii", $account, $page);
// Execute
$stmt-> execute();
// Bind results
$stmt-> bind_result($content);
// Fetch value
while ( $stmt-> fetch() ) {
echo $content;
}
// Close statement
$stmt-> close();
$mysqli-> close();
}
}

它说错误与PHP代码中的bind_result函数有关。我被困在这一点上。我尝试在 PHP 中增加内存限制.ini但这不起作用,无论如何我不应该占用那么多内存。

我想通了!您必须在bind_param之前存储结果...

$stmt-> store_result();

最新更新