Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysqli_fetch_的替代方案_Php_Mysqli - Fatal编程技术网

Php mysqli_fetch_的替代方案

Php mysqli_fetch_的替代方案,php,mysqli,Php,Mysqli,我有一个php mysqli代码,可以在我的本地服务器上找到一个,但是在我的服务器上使用它时,我得到了一个 Fatal error: Call to undefined function mysqli_fetch_all() in /home3/t561257/public_html/admin/database.php on line 49 代码的以下部分就是问题所在 function fetch_rows($queryname) { $result = $this->

我有一个php mysqli代码,可以在我的本地服务器上找到一个,但是在我的服务器上使用它时,我得到了一个

Fatal error: Call to undefined function mysqli_fetch_all() in /home3/t561257/public_html/admin/database.php on line 49
代码的以下部分就是问题所在

 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方法的类


我在本地服务器上使用的是php 5.5,因为服务器运行的是5.4.27,如果由于php安装而无法使用mysqli_fetch_all,我真的不知道如何修复它

  • 或者可能从Linux发行版的包存储库中安装另一个特定的包
  • 使用一个简单的循环:

    $data = [];
    while ($row = $result->fetch_assoc()) {
        $data[] = $row;
    }
    

  • 您甚至可以创建兼容性回退,而无需更改所有代码:

    if (!function_exists('mysqli_fetch_all')) {
        function mysqli_fetch_all(mysqli_result $result) {
            $data = [];
            while ($data[] = $result->fetch_assoc()) {}
            return $data;
        }
    }
    

    另一种选择是
    PDO
    我现在会把它作为我最后的选择试试
    phpinfo()以显示可用的数据库连接器。如果mysqli不可用,请与您的主人联系。或者,使用PDO。此函数仅在mysqli使用mysqlnd编译时可用。@deceze这对meMan来说似乎是个问题,你刚刚救了我一命。我在共享主机上,所以我遵循了你的第二条指令,它工作得很好。多亏了一个lot,您甚至可以创建一个兼容性回退,而无需更改所有代码:
    如果(!function_存在('mysqli_fetch_all'))function mysqli_fetch_all(mysqli_result$result)…。
    出于某种原因,您的替代函数在最后使用PHP5.3返回一条空记录。我的编辑:
    if(!function_exists('mysqli_fetch_all')){function mysqli_fetch_all(mysqli_result$result){$data=array();而($x=$result->fetch_assoc())if(!empty($x))$data[]=$x;return$data;}