我遇到了最奇怪的错误。首先是我非常简单的代码:
<!DOCTYPE html>
<html>
<header>
<link rel="stylesheet" type="text/css" href="/style.css" />
</header>
<body>
<?php
require_once 'includes/config.php';
// Create connection
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATA);
if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
//get safety sheat fields
$query="SELECT `fields` FROM `subforms` WHERE `id`=1 LIMIT 1";
$stmt = $conn->prepare($query);
$stmt->bind_result($fields);
$stmt->execute();
if (!$stmt->fetch()) {
echo 'error: no such form';
die();
}
die();
很简单。 require 仅获取 mysql 数据库的常量。
此代码在我的 xampp 设置上运行良好,但当我将它放在 linux 服务器上时,我得到:
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 4294967296 bytes) in /home/[path to files I don't wish to make public]/test.php on line 20
第 20 行 $stmt->bind_result($fields);
我真的不明白这是怎么可能的,也不知道去哪里寻找解决方法。有什么想法吗?
最佳答案
通过添加解决
$stmt->store_result();
在 bind_result
行之前。仍然很奇怪,它试图保留一个 longtext 可能存储的整个 4GB。我想我确实需要增加 ram 或缩小字段,以防字段被填满。
关于php - 为什么 php 试图使用 4GB 来 bind_results,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35192030/