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.
Solution: Call to Undefined Function Mysql_connect()
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.
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.
- 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 PHP versions.
Enjoy Debugging 🙂