Home > Backend Development > PHP Tutorial > Why Am I Getting a PHP Fatal Error: Call to Undefined Function mysqli_connect()?

Why Am I Getting a PHP Fatal Error: Call to Undefined Function mysqli_connect()?

Patricia Arquette
Release: 2025-01-03 07:57:39
Original
567 people have browsed it

Why Am I Getting a PHP Fatal Error: Call to Undefined Function mysqli_connect()?

Debugging PHP Fatal Error: Call to Undefined Function mysqli_connect()

The "Fatal error: Call to undefined function mysqli_connect()" is a common error that may arise when trying to establish a database connection using PHP.

In your case, you mentioned that you copied your PHP scripts from one server to another, where you're encountering this error. The issue likely stems from the fact that mysqli_connect() is not recognized by the PHP environment on your new server.

The code you provided for connecting to your database using mysqli_connect() is valid. However, the error suggests that the mysqli extension is missing or not properly installed on your new server.

To rectify this issue, you need to install the PHP MySQLi extension on your new server. You can do this using the following command via SSH:

sudo apt install php-mysqli
Copy after login

This command will install the necessary extension, allowing you to use the mysqli_connect() function to establish a database connection.

Ensure that you restart your web server (e.g., Apache or Nginx) after installing the extension for the changes to take effect. Once you do that, the "Fatal error: Call to undefined function mysqli_connect()" should be resolved, and you will be able to successfully connect to your database using PHP.

The above is the detailed content of Why Am I Getting a PHP Fatal Error: Call to Undefined Function mysqli_connect()?. 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