本文介绍了耗尽的允许内存大小为134217728字节(尝试分配4294967296字节)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目使用开源PHP MySQL库 https://github.com/ajillion /PHP-MySQLi-Database-Class

My project uses an open source PHP MySQL library https://github.com/ajillion/PHP-MySQLi-Database-Class

但是该项目的年中报告:致命错误:/home1/flipalbu/public_html/kvisofttest/login-admin/Lib/class.MysqliDb.php中的134217728字节的已用尽内存大小(尝试分配4294967296字节)在第422行上",此错误,

But the project mid-year report: "Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967296 bytes) in / home1/flipalbu/public_html/kvisofttest/login-admin/Lib/class.MysqliDb.php on line 422" This error ,

我的服务器是:linux x86_64

My server is: linux x86_64

PHP版本5.4.17

PHP Version 5.4.17

Mysql版本:5.5.32

Mysql Version: 5.5.32

memory_limit = 128M

memory_limit = 128M

第422行:call_user_func_array (array ($ stmt, 'bind_result'), $ parameters);

查询部分代码:

    $ db = new MysqliDb ('LocalHost', 'root', 'PASSWD', 'DB');
$ wqdb = $ db-> query ("SELECT * FROM db_table");
foreach ($ wqdb as $ row) {
     $ con. = $ row ['ID'];
}
echo $ con;

有什么办法解决吗?

/**错误代码**/

 protected function _dynamicBindResults(mysqli_stmt $stmt)
        {
            $parameters = array();
            $results = array();

            $meta = $stmt->result_metadata();

            $row = array();
            while ($field = $meta->fetch_field()) {
                $row[$field->name] = null;
                $parameters[] = & $row[$field->name];
            }

            call_user_func_array(array($stmt, 'bind_result'), $parameters);

            while ($stmt->fetch()) {
                $x = array();
                foreach ($row as $key => $val) {
                    $x[$key] = $val;
                }
                array_push($results, $x);
            }
            return $results;
        }

推荐答案

我在这里阅读了此错误报告: https://bugs.php.net/bug.php?id=51386

I read this bug report here: https://bugs.php.net/bug.php?id=51386

您的问题似乎发生了,因为表的列中有longbloblongtext.

Your problem seems to happen because there is a longblob or longtext in the columns of the table.

longtext/longblob的最大长度为4294967295 [4GB],这就是mysqli尝试为缓冲区分配该内存以确保没有丢失的原因.我建议您使用mediumtext(最大长度为16777215 [16MB]),通常对于所有内容都应该足够.

longtext / longblob have a maximum length of 4294967295 [4GB] thats why mysqli tries to allocated that memory for the buffer to be sure nothing is lost. I would suggest that you use mediumtext (16777215 [16MB] max length), that should be enough for everything usually.

更新:因为这个答案看到了一些活动,所以我在Phil_1984中添加了此解决方案(请参阅评论)

Update:Because this answer has seen some activity I add this solution from Phil_1984 (see comments)

=>如果使用$stmt->store_result(),则可以将mysqli与longblob/longtext一起使用,而不会出现错误.

=> If you use $stmt->store_result() you can use mysqli with longblob / longtext without getting the error.

-

旧答案:我建议您将列更改为另一种类型(中文本)或使用PDO(我认为它不存在该问题).但是如果您想将该列保留为长文本,则必须切换mysql库

Old Answer:I suggest that you either change the column to another type (mediumtext) or use PDO (i think it doesnt have that problem). but if you want to keep the column as longtext, you have to switch your mysql library

PHP Dev的报价:

Quote from PHP Dev:

这篇关于耗尽的允许内存大小为134217728字节(尝试分配4294967296字节)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 18:51