[SOLUTION] Fatal Error: Uncaught Error: Call to Undefined Function Mysql_connect()

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.

PHP -version

Error Reason

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.

Solution 1

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.

Solution 2

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.

Solution 3

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.

Conclusion

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 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Read previous post:
mysqli_num_rows() expects parameter 1 to be mysqli_result
[SOLUTION] Warning: Mysqli_num_rows() Expects Parameter 1 to Be Mysqli_result

Mysqli_num_rows() expects parameter 1 to be mysqli_result is one of the most basic kinds of errors that occur in PHP...

Close