問(wèn)題描述
我有一個(gè) php-mysqli 代碼可以找到我的本地服務(wù)器,但是在我的服務(wù)器上使用它時(shí)我得到了一個(gè)
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
下面這部分代碼就是問(wèn)題所在.
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 方法的類(lèi).
$db_link is the class which has the method fetch_rows.
我在本地服務(wù)器上使用 php 5.5,因?yàn)榉?wù)器運(yùn)行的是 5.4.27 我真的不知道如何修復(fù)它
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
不可用,因?yàn)槟?PHP 安裝 沒(méi)有用mysqlnd編譯,你有兩個(gè)選擇:
If mysqli_fetch_all
is not available because your PHP installation was not compiled with mysqlnd, you have two options:
- 使用 mysqlnd 重新編譯 PHP 或者可能從您的 Linux 發(fā)行版安裝另一個(gè)特定的包包存儲(chǔ)庫(kù).
使用一個(gè)簡(jiǎn)單的循環(huán):
- 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;
}
您甚至可以創(chuàng)建兼容性回退,而無(wú)需更改所有代碼:
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;
}
}
這篇關(guān)于需要 mysqli_fetch_all 的替代方案的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!