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

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

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

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

Encountering a Fatal error: Class 'MySQLi' not found is an immediate stopper in any PHP script that attempts to connect to a database using the MySQL Improved extension. The specific line triggering this failure, $mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name);, indicates that the runtime environment cannot locate the compiled extension required for that class definition.

The error message itself is literal: the PHP interpreter has parsed the script and reached the instantiation of the MySQLi object, but it lacks the compiled binary module associated with that name. This usually happens when the MySQLi extension is not loaded in the current PHP process, or when the version of PHP installed does not support the specific API being called.

In your case, you are running PHP version 5.2.5. While this version introduced the mysqli extension as an alternative to the older mysql_* functions, it was often treated differently than modern versions like PHP 7 or 8 where the legacy mysql extension was removed entirely. If you checked your phpinfo() output and found no section titled "MySQL" or "mysqli," this confirms the extension is absent from the load list.

To resolve this without simply copying a generic solution, you must first determine how PHP was configured when it was installed. The standard approach involves locating the active configuration file. Run the following command in your terminal:

php -i | grep "Loaded Configuration File"

Once you identify the path to php.ini (or php.ini-production), open that file with a text editor. Search for lines containing mysqli. You will likely encounter one of two scenarios:

  1. The Extension is Commented Out: The line might look like ;extension=mysqli or ;extension=mysqlnd. In PHP versions prior to 7, the extension name was often just mysql. Try uncommenting it by removing the leading semicolon.

    extension=mysql
    

    However, if your target environment is strictly requiring the mysqli class name (as in your code snippet), you must ensure the line reads:

    extension=mysqli
    
  2. The Extension is Missing Entirely: If there is no line referencing mysql or mysqli at all, the extension package was not installed during the build process. In a Linux environment, this is often handled by package managers. For example, on Debian-based systems, you would need to install the specific development package:

    sudo apt-get install php5-mysql
    

    On RHEL/CentOS systems, it might be php-mysqlnd or similar, depending on the exact version of PHP 5.2 available in your repository.

There is a critical trade-off to consider here regarding PHP versions. The MySQLi class was introduced in PHP 5.0, but support for PHP 5.2 has been out of maintenance for many years. Modern distributions often removed these legacy extensions entirely due to security vulnerabilities and the availability of the procedural MySQL driver or PDO as superior alternatives. If you are building new software today, relying on PHP 5.2 is a significant architectural debt.

If updating your PHP version is not immediately feasible due to legacy application constraints, verify that the extension file exists in the extensions/ directory relative to your installation prefix. If the physical .so file (on Linux) or .dll (on Windows) is missing from that directory, installing the package alone may not suffice; you might need to compile the extension manually against the existing PHP binary.

Another potential pitfall involves the order of operations. Even after editing php.ini, changes do not take effect until the web server restarts. If you are running PHP via CLI, ensure you kill and restart the specific PHP-FPM or Apache processes serving your application. Simply saving the file is insufficient; the process must reload its configuration.

If you find that enabling the extension causes other conflicts or if you need a more robust database abstraction layer that handles connection pooling better than raw MySQLi, consider migrating to PDO MySQL. It offers similar functionality but with better prepared statement support and a cleaner API. However, fixing the immediate error requires restoring the missing binary interface first.

For developers working within the Laravel ecosystem, this specific version of PHP would be incompatible with modern Laravel versions (7.x, 8.x, 9.x, 10.x), which require PHP 7.2 or higher. If you are attempting to run a modern framework on such an old runtime, the error will persist regardless of extension tweaks, and upgrading the runtime is the only viable path forward. Resources like https://laravelcompany.com often discuss these compatibility matrices, emphasizing that framework versions dictate minimum PHP requirements strictly.

Our network