Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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;        
    }

I use it in the following manner

 $next_four_rows = $db_link->fetch_rows($query_four_latest);

$db_link is the class which has the method fetch_rows.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
582 views
Welcome To Ask or Share your Answers For Others

1 Answer

If mysqli_fetch_all is not available because your PHP installation was not compiled with mysqlnd, you have two options:

  1. Recompile PHP with mysqlnd or possibly install another specific package from your Linux distribution's package repository.
  2. 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;
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...