Home > Backend Development > PHP Tutorial > Why is My PHP Code Throwing a 'Fatal error: Class 'MySQLi' not found' Error?

Why is My PHP Code Throwing a 'Fatal error: Class 'MySQLi' not found' Error?

Barbara Streisand
Release: 2024-12-10 15:14:11
Original
416 people have browsed it

Why is My PHP Code Throwing a

MySQLi Not Found During Installation

While following a tutorial, you may encounter the error "Fatal error: Class 'MySQLi' not found" on line 8. This error indicates that the MySQLi extension is not enabled for your PHP installation.

The code on line 8 attempts to create a new MySQLi object using the $mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name); statement. However, if the MySQLi extension is not installed or enabled, this code will fail.

Solution

To resolve this issue, you need to install the MySQLi extension. You can do this by following these steps:

  1. Check if the PHP intallation is enabled. You can do this by checking the php.ini file, and searching for the line extension=mysqli. If the line is commented, remove the comment (;) from the line.
  2. If the extension is not enabled, you need to install the MySQLi extension. This can be done by downloading the MySQLi extension from PECL (https://pecl.php.net/package/mysqli), and then installing it using the phpize and make commands.
  3. After installing the extension, make sure to restart the web server to apply the changes.

Once you have installed the MySQLi extension, you should be able to use the MySQLi class without any errors.

The above is the detailed content of Why is My PHP Code Throwing a 'Fatal error: Class 'MySQLi' not found' Error?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template