If you are getting “fatal error: uncaught error: Call to undefined function mysql_connect()” in your PHP project, then do not worry. Because here, we will resolve the call to undefined function mysql_connect() error step by step.
Index
To solve the Fatal Error: Uncaught Error: Call to Undefined Function Mysql_connect(), first of all, check for a PHP version of your working environment by typing the below code into your terminal.
PHP -version
Now if your PHP version is 7.0 or above then we have to use mysqli_connect() instead of mysql_connect() function.
From PHP version 7.0, MySQL commands are deprecated, and no more default available in PHP to use. So we can not use any Mysql command like mysql_connect(), mysql_query(), mysql_num_rows(), mysql_fetch_array(), mysql_fetch_assoc(), etc.
Read Also: Things You Should Know About PHP Latest Version 7.0
In PHP 7.0, Mysqli commands are default available to connect with the MySQL database. For PHP version 7.0 or above working environment, we have to use mysqli_connect, mysqli_query, mysqli_num_rows, mysqli_fetch_array, mysqli_fetch_assoc, etc.
If your project uses Mysql queries in the entire project, then you might not be able to change queries for the whole project. At that time, you should change your working environment configurations.
To resolve that, change your PHP version from 7 to 5.6 stable.
In Cpanel, changing the PHP version is a piece of cake.
I hope this article will help you to resolve the Call to Undefined Function Mysql_connect() error.
The best practice is to keep updated our projects with the latest configurations and functions, so think twice before using older PHP versions.
Enjoy Debugging 🙂
There is a reason big-name companies like CNN use WordPress. WordPress is a popular content…
In this tutorial, I'm going to show you how to install MySQL on your computer.…
Download Turbo C++ for windows 10 in just 7 Mb and run your first C++…
We can redirect any webpage to any other or redirect the whole domain or website…
There are lots of methods to redirect pages, like refresh-redirect from META tag, redirect from…
Include files in PHP are used in appending various global or config files. We can…