John Davidson

php - Fatal error: Call to undefined function mysqli_connect()

0 comments
Message:


For 2 days now I'm trying to solve this, but unfortunately no result. Let me tell you my story about the problem. I've bulid an application on a site, and the application deals with the reviews. But, I'm trying to put it on another site, and I copyed the php files, the sql file from the old site, and moved them to the new site (they are on different FTP servers). When I'm trying to go to the pages from the application, I receive this FATAL ERROR:




Fatal error: Call to undefined function mysqli_connect()




The code that I wrote to connect to the database is this (with hidden credentials):



$con = mysqli_connect("","*the_name*","*the_pass*","*the_database*");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}


Why do I get the error? It works on the old server, and the code I think it's not the problem, because it works on localhost, and on the new server it doesn't. Can anyone help me?



My Answer:
It seems like the mysqli extension is not enabled on the new server. You can check if the mysqli extension is enabled by creating a phpinfo file and checking the output.

To create a phpinfo file, create a new PHP file with the following code:

php
phpinfo();
?>


Save this file as phpinfo.php and upload it to the root directory of your new server. Then, access this file in your browser (e.g. http://yourdomain.com/phpinfo.php) and search for mysqli in the output.

If mysqli is not enabled, you will need to enable it in your server's PHP configuration. This can usually be done by editing the php.ini file on your server and uncommenting the line that includes the mysqli extension.

After making this change, you may need to restart your server for the changes to take effect. Once mysqli is enabled, your code should work without any issues.

Rate this post

4 of 5 based on 8725 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us