Home  >  Article  >  Backend Development  >  Solution to PHP Fatal error: Call to undefined function mysqli_connect()

Solution to PHP Fatal error: Call to undefined function mysqli_connect()

WBOY
WBOYOriginal
2023-06-23 09:40:501977browse

When writing web applications using PHP, MySQL database is often used to store data. PHP provides a way to interact with the MySQL database called MySQLi.

However, sometimes when using MySQLi, you will encounter an error message, as shown below:

PHP Fatal error: Call to undefined function mysqli_connect()

This The error message means that PHP cannot find the mysqli_connect() function. The cause of this problem is missing MySQLi extension.

Before solving this problem, you first need to confirm whether the MySQLi extension is installed. You can check by following these steps:

  1. Type php -m in the terminal window to view the currently installed PHP extensions.
  2. Find the mysqli extension in the list. If it is found, MySQLi is installed. Otherwise, it needs to be installed.

If MySQLi is not installed, you can install it through the following steps:

  1. Run the following command in the terminal: sudo apt-get install php-mysql.
  2. After the installation is complete, restart the web server.

If MySQLi has been installed but the above error still occurs, please follow the steps below to troubleshoot:

  1. Confirm that the mysqli extension option is not commented out in PHP.ini.
  2. Confirm whether the web server has been restarted.
  3. Confirm whether the mysqli extension options in PHP.ini are the same as the options in the php.ini.sample file.
  4. Try reinstalling the MySQLi extension.
  5. Check whether the PHP code is correct.

These steps should help you solve the PHP Fatal error: Call to undefined function mysqli_connect() problem. If it still doesn't work, try posting your question on the PHP forum or community for more help.

The above is the detailed content of Solution to PHP Fatal error: Call to undefined function mysqli_connect(). 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