Home >Backend Development >PHP Tutorial >Why Am I Getting the 'Fatal error: Call to undefined function mysqli_connect()' Error in PHP?

Why Am I Getting the 'Fatal error: Call to undefined function mysqli_connect()' Error in PHP?

Linda Hamilton
Linda HamiltonOriginal
2024-12-16 01:08:09478browse

Why Am I Getting the

Troubleshooting "Fatal error: Call to undefined function mysqli_connect()": A Step-by-Step Guide

The "Fatal error: Call to undefined function mysqli_connect()" error commonly occurs when a PHP script attempts to use the mysqli_connect() function without it being properly loaded or available.

Possible Causes:

  • PHP Extension Not Loaded: Ensure that the PHP MySQLi extension (php-mysqli) is enabled on your server. You can check this by running the following command in the terminal:
php -m | grep mysqli

If you see "mysqli" listed, the extension is enabled. If not, proceed to the next step.

Solution:

To install the PHP MySQLi extension on Ubuntu/Debian systems, run the following command:

sudo apt install php-mysqli

Version Compatibility:

Confirm that the installed PHP MySQLi extension is compatible with your PHP version. The error message may also include information about the missing version.

Code Issue:

Review your PHP code carefully. Ensure that the connection parameters passed to mysqli_connect() are correct (host, user, password, database).

Confirm Host Access:

Verify that your PHP script has permission to connect to the MySQL server. This can be done by checking your MySQL configuration file (usually /etc/mysql/my.cnf) or by contacting your server administrator.

Final Note:

Once the necessary changes have been made, restart your web server (e.g., Apache, Nginx) to apply the changes. The mysqli_connect() function should now be available, resolving the fatal error.

The above is the detailed content of Why Am I Getting the 'Fatal error: Call to undefined function mysqli_connect()' Error in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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