Troubleshooting the "PHP Fatal Error: Call to undefined function MYSQL_CONNECT()" Error Make it Rain Paper

  • Databases, cPanel
  • 0

Pre-requirements

  • Access to your cPanel account or root access via SSH.
  • Basic knowledge of PHP and MySQL configuration.

Why Does This Error Occur?

This error occurs when a script tries to connect to a MySQL database using the deprecated mysql_connect() function, which was removed in PHP 7.0. If you're using a modern PHP version (7.0 or later), and your application is still using mysql_connect, you will encounter this fatal error. Here's an example from an error log:

[18-May-2023 12:40:06 America/Los_Angeles]
PHP Fatal error:  Call to undefined function MYSQL_CONNECT() in /home/$user/public_html/includes/settings.inc.php on line 19

Steps to Troubleshoot the Error

1. Check PHP Version and Compatibility

The mysql_connect function was deprecated in PHP 5.5 and removed in PHP 7.0. If your website requires mysql_connect, you need to either:

  • Downgrade your PHP version to a pre-7.0 version like PHP 5.6.
  • Upgrade the application to use newer MySQL extensions like mysqli or PDO_MySQL.

If you are a customer on a hosting plan with us, you can choose from packages that support older PHP versions via EOL PHP Hosting.

2. Check for MySQL Extension in PHP

If you have configured your website to use PHP 5.6 but still encounter this error, it's likely that the mysqlnd extension is not installed or enabled.

To resolve this, install the necessary extension using EasyApache 4 or yum (requires root access):

yum install ea-php56-php-mysqlnd

3. Remove suPHP_ConfigPath Configuration

If your website was configured with suPHP_ConfigPath under EasyApache 3, this can cause issues loading extensions. Modify the .htaccess file in the document root or above and comment out the suPHP_ConfigPath directive:

# suPHP_ConfigPath /path/to/php.ini

Alternatively, rename or delete the custom php.ini file. You can create a new custom php.ini using the MultiPHP INI Editor in cPanel.

4. Ensure MySQL Extension Is Enabled in PHP Selector

If your hosting environment uses CloudLinux with CageFS, the PHP Selector may take precedence over MultiPHP Manager. Ensure that the "mysqlnd" extension is enabled in the PHP Selector:

  1. Go to PHP Selector in cPanel.
  2. Select your PHP version and enable the "mysqlnd" extension.

Possible Solutions for Compatibility Issues

Option 1: Upgrade Your Application or Plugin Code

If you're using WordPress or a CMS, enable debugging in wp-config.php to identify incompatible plugins or themes:

define( 'WP_DEBUG', true );

Alternatively, use WP-CLI to deactivate the offending plugins:

wp plugin deactivate $plugin-name

Option 2: Enable the Appropriate MySQL Extension

In CloudLinux's PHP Selector or MultiPHP Manager, ensure that one of the following sets of extensions is enabled:

mysqlnd
nd_mysql
nd_mysqli
nd_pdo_mysql

Or:

mysql
mysqli
pdo_mysql

Option 3: Remote Connection and MySQL Issues

If you're trying to connect to a remote MySQL server and encountering the error:

Error NO. 2003
Can't connect to MySQL server on '1.2.3.4' (10060)

This is likely due to a firewall block or network issue. Use Nmap to test the connection:

nmap -sT 1.2.3.4 -p 3306

If a filter is detected, it indicates a firewall issue. Contact your hosting provider to allow the IP through the firewall, or if you have root access, modify the firewall rules to permit the connection.

The "Call to undefined function MYSQL_CONNECT()" error usually occurs due to PHP version incompatibility or missing MySQL extensions. By following these troubleshooting steps, you can resolve the issue by upgrading your application, enabling the correct MySQL extensions, or downgrading the PHP version. If you're unsure about your configuration, contact your hosting provider for further assistance.

If you'd like to contribute to this tutorial or found an error, email us at team+editorial@webhostingm.com.


Did this answer help?

« Back