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 are going to resolve the call to undefined function mysql_connect() error step by step.
Check for PHP Version
First of all, check for a PHP version of your working environment by typing below code into your terminal.
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.
In PHP 7.0, Mysqli commands are default available to connect with the MySQL database. So 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, just change your PHP version from 7 to 5.6 stable.
In Cpanel, changing the PHP version is a piece of cake.
- Just go to your Cpanel and look for Select PHP Version and click on it.
- After that, in the new window, you will have an option to change the PHP version of the working environment, even more, you can see the PHP extension list to Enable or Disable.
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 versions of PHP.
Enjoy Debugging 🙂