php 致命错误:调用未定义的方法 mysqli_result::fetch_all()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11664536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: Call to undefined method mysqli_result::fetch_all()
提问by Stokres
I have problems with PHP in Ubuntu 10.04. When I try use mysqli_result::fetch_all this error appears:
我在 Ubuntu 10.04 中遇到 PHP 问题。当我尝试使用 mysqli_result::fetch_all 时出现此错误:
Call to undefined method mysqli_result::fetch_all()
调用未定义的方法 mysqli_result::fetch_all()
However, it works in Windows XP.
但是,它适用于 Windows XP。
The Code:
编码:
$result = $this->dbh->query('SELECT [...] ');
return $result->fetch_all(MYSQLI_ASSOC);
I don't want to use fetch_assocwith a loop because I send the result to another layer for processing.
我不想将fetch_assoc与循环一起使用,因为我将结果发送到另一层进行处理。
I'm using PHP 5.4.4. and with php -m | grep mysqlthe mysqlnd module it doesn't appear. How can I install it? Could that be the problem?
我正在使用 PHP 5.4.4。并使用php -m | grep mysqlmysqlnd 模块它没有出现。我该如何安装?这可能是问题吗?
回答by Ibrahim Azhar Armar
mysqli_result::fetch_all() requires MySQL Native Driver (mysqlnd).
mysqli_result::fetch_all() 需要 MySQL 本机驱动程序 (mysqlnd)。
chances are you might be missing it.
你可能会错过它。
have a look at this posts, that might help you.
看看这个帖子,可能对你有帮助。
回答by wonton
fetch_all consumes more memory than fetch_array() and has other detrimental side effects, so fetch_array/fetch_assoc are preferred.
fetch_all 比 fetch_array() 消耗更多的内存并具有其他不利的副作用,因此 fetch_array/fetch_assoc 是首选。
Detailed from PHP documentation:
来自 PHP 文档的详细说明:
Available only with mysqlnd.
As mysqli_fetch_all() returns all the rows as an array in a single step, it may consume more memory than some similar functions such as mysqli_fetch_array(), which only returns one row at a time from the result set. Further, if you need to iterate over the result set, you will need a looping construct that will further impact performance. For these reasons mysqli_fetch_all() should only be used in those situations where the fetched result set will be sent to another layer for processing.
仅适用于 mysqlnd。
由于 mysqli_fetch_all() 在单个步骤中将所有行作为数组返回,因此它可能比某些类似函数(例如 mysqli_fetch_array() 一次仅从结果集中返回一行)消耗更多内存。此外,如果您需要迭代结果集,您将需要一个循环结构,这将进一步影响性能。出于这些原因,mysqli_fetch_all() 应该只在获取的结果集将被发送到另一层进行处理的情况下使用。
If you really want to use it, you have to install mySQL with native drive (mysqlnd) Example installation:
如果你真的要使用它,你必须安装带有本机驱动器的mySQL(mysqlnd)示例安装:
./configure --with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
On Ubuntu you can just do
在 Ubuntu 上你可以做
sudo apt-get install php5-mysqlnd
回答by Timur
http://www.php.net/manual/en/mysqli-result.fetch-all.php
http://www.php.net/manual/en/mysqli-result.fetch-all.php
Available only with mysqlnd.
仅适用于 mysqlnd。
Notes about enabling mysqlnd: http://www.php.net/manual/en/mysqlnd.install.php
关于启用的注意事项mysqlnd:http: //www.php.net/manual/en/mysqlnd.install.php

