How to solve "Fatal error: Class 'MySQLi' not found"?

You can check if the mysqli libraries are present by executing this code:

if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
    echo 'We don\'t have mysqli!!!';
} else {
    echo 'Phew we have it!';
}

If you're calling "new mysqli(..)" from within a class that is namespaced, you might see a similar error Fatal error: Class 'foo\bar\mysqli' not found in. The way to fix this is to explicitly set it to the root namespace with a preceding backslash like so:

<?php 
$mysqli = new \MySQLi($db_server, $db_user, $db_pass, $db_name);

Sounds like you just need to install MySQLi.

If you think you've done that and still have a problem, please post your operating system and anything else that might help diagnose it further.


If you are on Ubuntu, run:

 sudo apt-get install php-mysqlnd

And don't forget to restart the php service after this (Apache or php-fpm depends on the setup).

Tags:

Php

Mysqli