The Wonderful World of Linux A mostly dead cpanel/linux blog

Call to undefined method mysqli_result::fetch_all()

If you have ever experienced this error and you are positive that mysqli is installed, the issue is probably because you need mysqlnd. Checkout the following code snippet:

<?php
    $conn = new mysqli($servername, $username, $password, $database, $port);
    $r = $conn->query("SELECT * FROM `dummy`", MYSQLI_STORE_RESULT);
    $arr = FALSE;
    if($r !== FALSE)
    {
        echo "<br />Vardump:<br/>";
        var_dump($r);
        echo "<br /><br />Checking if methods exist:<br/>";     
        echo "<br />fetch_assoc() method exists? ";
        var_dump(method_exists($r, 'fetch_assoc'));
        echo "<br />fetch_all() method exists? ";
        var_dump(method_exists($r, 'fetch_all'));       
        echo "<br />";
        $arr = $r->fetch_all(MYSQLI_ASSOC);
        $r->free();
    }
    print_r($arr);

When running this, you may encounter the following error:

fetch_assoc() method exists? bool(true)
fetch_all() method exists? bool(false)

The fetch_all() method within mysqli actually relies on mysqlnd being installed at compile time. If you are using CentOS, atomicorp has rpm’s within their repo that should install this:

http://www6.atomicorp.com/channels/atomic/centos/6/i386/RPMS/

Debian can be found here:

http://packages.debian.org/sid/php5-mysqlnd

If you are running cPanel, add this:

--with-mysqli=mysqlnd

To this:

/var/cpanel/easy/apache/rawopts/all_php5

And then run easyapache:

/scripts/easyapache --build

Now everytime you need to recompile, that flag will always be tacked on. Enjoy!