Troubleshooting "Fatal error: Class 'MySQLi' not found" in PHP
When encountering the error "Fatal error: Class 'MySQLi' not found," it indicates that the MySQLi extension is not enabled or configured correctly in your PHP environment. Here's how to resolve this issue:
Checking PHP Version
Ensure that you are running a PHP version that supports MySQLi. Version 5.2.5 is outdated and does not include MySQLi by default. Consider upgrading to a more recent PHP version.
Installing MySQLi Extension
If you are using a compatible PHP version, you need to install the MySQLi extension. You can typically do this:
For Linux/Unix:
yum install php-mysqli
or
apt-get install php-mysqli
For Windows:
Enabling MySQLi Extension
After installing MySQLi, you must ensure that it is enabled in your php.ini configuration file. Add the following line to your php.ini file:
extension=mysqli.so
Restart Web Server
Once you have installed and enabled MySQLi, restart your web server (e.g., Apache or Nginx) to apply the changes.
Verifying Installation
Check your PHPInfo page (e.g., by creating a script with phpinfo();) and look for the "mysqlnd" section. This section should list MySQLi as one of the available extensions.
Sample Code
Here's a modified version of your sample code, assuming MySQLi is now installed and enabled:
<?php $mysqli = new mysqli($db_server, $db_user, $db_pass, $db_name); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; }
The above is the detailed content of How to Fix the 'Fatal error: Class 'MySQLi' not found' PHP Error?. For more information, please follow other related articles on the PHP Chinese website!