Fatal error: Call to undefined method mysqli_result::fetch_all()
Encountering the Call to undefined method mysqli_result::fetch_all() error usually points to a specific divergence in how your PHP environment handles database connections, rather than a bug in your logic. In this case, the root cause is almost certainly the absence of the MySQL Native Driver (mysqlnd). The fact that the code works on Windows XP but fails on Ubuntu 10.04 highlights an OS-dependent configuration difference: Windows often bundles a legacy ODBC driver stack or a pre-installed native driver, whereas Linux distributions typically ship with the standard libmysqlclient library unless mysqlnd is explicitly enabled.
The error occurs because fetch_all() was introduced in PHP 5.3 specifically to work with the mysqlnd driver. When using the older libmysqlclient extension (which appears absent from your php -m | grep mysql output), that method simply does not exist on the mysqli_result object, regardless of your PHP version. Your attempt to avoid looping through fetch_assoc is a valid architectural decision for passing bulk data to other layers, but you must ensure the underlying driver supports it.
To resolve this on Ubuntu 10.04, you need to install and enable the mysqlnd module. On older Debian/Ubuntu systems, this package was often named php5-mysql. Installing it should pull in the native driver support required for modern mysqli features. Run the following command as root:
sudo apt-get update
sudo apt-get install php5-mysql
After installation, you must verify that the extension is actually loaded into your PHP process. Create a test file like info.php with phpinfo() and look for a section titled "mysqli" where it explicitly lists "mysqlnd". If the section exists but doesn't mention mysqlnd, check /etc/php5/mods-available/ for an enabled .disable or .dist.ini file. You may need to manually enable the extension in your php.ini by uncommenting the line:
extension=php_mysqlnd.so
Once confirmed, restart your web server (Apache) or CLI PHP process to apply changes.
If you are unable to install mysqlnd due to repository limitations on older systems like Ubuntu 10.04, you have a few pragmatic alternatives. You can switch to the legacy mysql_fetch_all() function from the procedural MySQL API, though this is generally discouraged due to performance and security implications. Alternatively, if you require high performance or need to leverage PDO's native support for fetching all rows at once, migrating to PDO MySQL is a robust strategy. PDO works seamlessly with mysqlnd and provides similar functionality via $stmt->fetchAll().
$stmt = $this->dbh->prepare('SELECT [...]');
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
For modern Laravel projects, specifically those hosted on https://laravelcompany.com, the framework defaults to PDO by default. This means the mysqli class is often unused entirely, preventing this specific error from occurring in the first place if your configuration remains consistent. However, if you are forced to stick with the legacy mysqli extension on an older OS, installing the correct driver package is the only way to unlock methods like fetch_all.
Be cautious when mixing drivers or assuming cross-platform compatibility without verifying the active extensions. Always inspect the output of phpinfo() before debugging application logic; the missing method is a runtime symptom of a missing binary dependency, not a coding error.