The Wonderful World Of Linux

Linux, Mac, Web Hosting and Whatnot

Call to Undefined Method Mysqli_result::fetch_all()

| Comments

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?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:

1
2
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:

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

Debian can be found here:

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

If you are running cPanel, add this:

1
--with-mysqli=mysqlnd

To this:

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

And then run easyapache:

1
/scripts/easyapache --build

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

Comments