Fatal error: Call to undefined function mysql_connect() !!

February 13th, 2008

I was about to start using my first program on PHP5, then I received this irritating message.

I was using PHP4 these days, so this error was something which revisited after a long time. In PHP4 I new what it means and how to rectify.

The error indicates that PHP was unable to connect to the MySQL DB and it is basically an error on the PHP installation/ missing library file.

Generally, one need to check following things in order to troubleshoot the current situation.

Is it PHP5 on which this error happened and are its after you migrated to PHP5? If then, one small peiece of information for you. MySQL support is not enabled by default in PHP5. You can read http://in.php.net/manual/en/faq.databases.php#faq.databases.mysql.php5 for the reasons and how to troubleshoot.

Following are some other basic troubleshooting steps.

Windows System

  1. Make sure in your PHP.ini file , the mysql extension is enabled. Look for a line containing ‘extension=php_mysql.dll’ and if there is a semicolon in front of this, its not enabled. So remove the semicolon to enable it.
  2. Check for the extension directory path in php.ini – ‘extension_dir = “C:Program FilesPHP5ext”‘ . make sure the path is correct, and you have the extension files in it. For mysql extension, you will need php_mysql.dll .

With this much, if mysql is present, you should not be seeing the error message again

Linux System

Make sure PHP is compiled with mysql support. Check http://in.php.net/mysql on the installation instructions.

If you are using PHP5 , mysql is not enabled by default šŸ™ (This is where the problem starts). So if you have PHP already installed, consider removing it and recompiling from the source with mysql support.

There are easier methods to set up LAMP systems. Please checkĀ  my post about XAMPP too

Leave a Reply