需要mysqli_fetch_all的替代方法 [英] Alternative to mysqli_fetch_all needed
问题描述
我有一个php-mysqli代码,可以找到我的本地服务器,但是在我的服务器上使用它时,我得到了
I have a php-mysqli code that works find one my local server but on using it on my server i am getting a
Fatal error: Call to undefined function mysqli_fetch_all() in /home3/t561257/public_html/admin/database.php on line 49
代码的以下部分是问题所在.
The following part of the code is where the problem is.
function fetch_rows($queryname) {
$result = $this->connection->query($queryname);
$row = mysqli_fetch_all($result, MYSQLI_ASSOC);
return $row;
}
我以以下方式使用
$next_four_rows = $db_link->fetch_rows($query_four_latest);
$ db_link是具有方法fetch_rows的类.
$db_link is the class which has the method fetch_rows.
我正在本地服务器上使用php 5.5,因为该服务器正在运行5.4.27,我对如何解决它真的一无所知
I am using php 5.5 on my local server where as the server is running 5.4.27 I am really clueless on how to fix it
推荐答案
如果mysqli_fetch_all
不可用,因为您的PHP安装
If mysqli_fetch_all
is not available because your PHP installation was not compiled with mysqlnd, you have two options:
- 用mysqlnd重新编译PHP 或可能从Linux发行版的安装另一个特定的软件包软件包存储库.
-
使用一个简单的循环:
- Recompile PHP with mysqlnd or possibly install another specific package from your Linux distribution's package repository.
Use a simple loop:
$data = [];
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
您甚至可以创建兼容性后备,而无需更改所有代码:
You could even create a compatibility fallback, without needing to change all your code:
if (!function_exists('mysqli_fetch_all')) {
function mysqli_fetch_all(mysqli_result $result) {
$data = [];
while ($data[] = $result->fetch_assoc()) {}
return $data;
}
}
这篇关于需要mysqli_fetch_all的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!