While these troubleshooting steps are not by any means exhaustive, they constitute the majority of the issues relating to this and this will give a good head start.

Let's start with the basics:

 

Troubleshooting PHP Fatal error Call to undefined function MYSQL_CONNECT

If you take a look at your error_log file, you will see the presence of these:

[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

This occurs when trying to connect to a MySQL database using the mysql_connect function and the function is undefined or not available.

This often means that the MySQL extension is not installed or enabled in the PHP configuration.

The commonest cause for this error is when you are trying to use a modern PHP version on a website that uses the function, "mysql_connect".

mysql_connect was deprecated in PHP 5.5 and removed in PHP version 7.0.

For more information, please review the official PHP documentation at https://www.php.net/manual/en/function.mysql-connect.php

Check that out first, and adjust which is to downgrade the PHP version the application is using to a pre-PHP 7.0 version.

Customers hosting their website with us can select one of the packages at https://dashboard.webhostingmagic.com/store/eol-php-hosting to get this done.

If the website is configured properly to use PHP 5.6 or older via MultiPHP Manager or CloudLinux's PHP selector, and you see the correct version in a phpinfo page (if accessible), but are still seeing this error, this means the extension is not loaded.

1. If the mysqlnd extension is not installed.

To correct this, use the EasyApache 4 interface to install the correct extension on the PHP version, or use yum. This of course requires "root" access:

dnf | yum install ea-php56-php-mysqlnd

2. The website was configured with suPHP_ConfigPath in EasyApache 3

cPanel strongly advised against setting the [phprc_paths] section, the suPHP_ConfigPath directive, or setting the PHPRC environmental variable as doing so may trigger unexpected behavior.

The solution here would be to modify the .htaccess file in the document root or above and remove the "suPHP_ConfigPath" directive.

You can do this by commenting out (#) this entry from the (dot)htaccess file.

Or move the custom php.ini file out of the way (rename or delete).

This causes only the user's php.ini file to be loaded instead of all of the INIs required to load the extensions.

You can then create/edit custom php.ini using the MultiPHP INI Editor in cPanel.

3. The extension is not enabled in PHP Selector

If this is a CloudLinux server, and cPanel's MultiPHP Manager is set to "Inherit," and the user is in CageFS, this means that PHP Selector takes precedence. You will want to go into the PHP Selector options and make sure the "mysqlnd" extension is enabled.

To resolve this:

1. Upgrade the application, theme/template, and/or plugin/extension code:

First, enable the debug option in wp-config.php and find which WordPress plugin or theme is not compatible with PHP 7+.

If using WordPress Toolkit or Softaculous WordPress Manager, deactivate all the plugins and then selectively, activate them one by one to find the culprit.

You can also just rename the directory where the plugins are stored: /wp-content/plugins/.

If using WP-CLI, you can use:

wp plugin deactivate $plugin-name command

Once you find the cause, upgrade/replace the plugin and theme.

2. enabling the nd_mysqli extension in the PHP configuration and disabling the mysqli one:

This is an easy problem to fix since the hosting package at https://dashboard.webhostingmagic.com/store/eol-php-hosting allows you to selectively install such extensions.

To resolve this, visit the PHP Selector > Extensions.

Depending on the need, choose only one of the following sets:

mysqlnd
nd_mysql
nd_mysqli 
nd_pdo_mysql

or:

mysql
mysqli
pdo_mysql

 

Deeper?

So the possible explanation is that PHP offers three different APIs to connect to MySQL.

  • libmysqlclient works with mysql, mysqli, pdo_mysql extensions (PHP 4.4 - PHP 5.3);
  • mysqlnd works with nd_mysql, nd_mysqli, nd_pdo_mysql extensions (PHP 5.4 - PHP 7.1+).

 

Remote Connection and MySQL

If you are trying to log in to a local MySQL service server from a remote location and the client returns this error:

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

This probably indicates that a connection is unable to be obtained.

The cause is likely to be a firewall block or network issue.

You can check the cause using a tool such as Nmap:

nmap -sT 1.2.3.4 -p 3306

If the connection test returned a result of a filter, this would indicate that a firewall is preventing the connection. It is common practice to secure the MySQL service by preventing inbound connections to its listening port in the firewall.

If you are a website owner or hosting account admin without access to make server-wide configurations, then contact your web host security team.

In our case, that would be logging in and visiting our security team.

If you have "root" access, then consider allowing the IP you are connecting from through this restriction.

 

PHPMyAdmin via Web Hosting Manager Connection Issue

If you are a system admin with "root" access and trying to access PHPMyAdmin via Web Hosting Manager and see the following:

mysqli_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)

It is probably due to the permission set for the mysql.sock file.

First, use stat to verify the file permission is 0777:

stat /var/lib/mysql/mysql.sock

If incorrectly set, modify the file to use the proper permissions, and then try again.

There may be other possible causes you may check on including the possibility that:

  • The MySQL directory is missing from your CageFS configuration, thus websites have trouble connecting to MySQL from inside the CageFS or
  • That the mysql.sock file is somewhere else

Try to reset the MySQL server socket path to the default value in the /etc/my.cnf file.

 

Let's grep to find:

grep sock /etc/my.cnf

socket = /var/lib/mysql/mysql.sock

If your mysql.sock file is configured to a custom location in /etc/my.cnf file, symlink to the file in /var/lib/MySQL to your current mysql.sock file using the command (e.g. current mysql.sock is in the /home/mysql/ folder):

ln -s /home/mysql/mysql.sock /var/lib/mysql/mysql.sock

If another location for mysql.sock, then update the aforementioned command accordingly.

Then restart MySQL or MariaDB service either through Home >> Restart Services >> SQL Server (MySQL), or:

mysqld --validate-config /scripts/restartsrv_mysql

See How to validate server configuration settings

 

If you have CageFS enabled, run:

cagefsctl -M

Also, check to ensure that /var/lib/mysql is present in your cagefs.mp file:

grep mysql /etc/cagefs/cagefs.mp

If it is missing, add and execute:

cagefsctl --force-update

Was this answer helpful? 0 Users Found This Useful (0 Votes)