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

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

DDD
Release: 2024-12-31 22:39:10
Original
754 people have browsed it

Why Am I Getting the

Resolving "Fatal Error: Call to Undefined Function mysqli_connect()"

Problem Description:

A user encounters the error "Fatal error: Call to undefined function mysqli_connect()" when attempting to establish a connection to a MySQL database using PHP. The code responsible for connecting to the database appears to be correct and has been tested successfully on localhost and the previous server.

Solution:

The error indicates that the PHP extension for MySQL, "mysqli," is not installed or enabled. To resolve this issue, follow these steps:

  1. Install the mysqli Extension:

    Ubuntu/Debian:

    sudo apt install php-mysqli
    Copy after login

    CentOS/Red Hat:

    yum install php-mysqli
    Copy after login
  2. Restart Apache or Nginx:

    Restart your web server to activate the newly installed or enabled extension.

    Apache:

    sudo systemctl restart apache2
    Copy after login

    Nginx:

    sudo systemctl restart nginx
    Copy after login
  3. Verify Installation:

    Ensure that the extension has been successfully installed by creating a new PHP file and adding the following code:

    <?php
    if (function_exists('mysqli_connect')) {
        echo "mysqli_connect function is available";
    } else {
        echo "mysqli_connect function is not available";
    }
    ?>
    Copy after login

    Run the PHP file to verify the availability of the mysqli_connect function. It should display "mysqli_connect function is available".

By installing and enabling the mysqli extension, the user can establish a connection to the MySQL database and resolve the "Fatal error: Call to undefined function mysqli_connect()" error.

The above is the detailed content of Why Am I Getting the 'Fatal Error: Call to Undefined Function mysqli_connect()' in PHP?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template