How to fix Fatal Error: Call to undefined function mysql_connect() in WordPress

While using a WordPress website, you may come across such fatal errors:Fatal error: Uncaught Error: Call to undefined function mysql_connect(). This error usually indicates that the system you are using is not properlyConfiguration Databaseor the required PHP extensionsNot enabled. This tutorial will provide you with a detailed solution to help you troubleshoot this issue.

图片[1]-如何解决 WordPress Fatal Error: Call to undefined function mysql_connect() 的问题

Root causes of the problem

The main reasons for this error include:

  1. The database service is not running or is misconfigured.
  2. Extensions related to database interaction are not enabled in the PHP environment, such as the mysqliThe
  3. PHP Newer versionNo longer supported mysql_connect function.
  4. The required MySQL extensions are not properly loaded in the version of PHP used.

Below are the detailed steps to resolve the issue for those using the cPanel control panel.

Solution 1: Check the database operation status

First, verify that the database on the server is working properly:

  • If you are using a hosted server, check the status of the MySQL or MariaDB service through the hosting panel.
  • For a standalone server, use the following command to check if the service is running:sudo systemctl status mysql
图片[2]-如何解决 WordPress Fatal Error: Call to undefined function mysql_connect() 的问题
  • If the service is not running, use the following command to restart it:sudo systemctl start mysql

Solution 2: Enable PHP extensions via cPanel

If your server is running fine but the error persists, you can follow the steps below to check and enable the necessary PHP extensions via cPanel.

Step 1: Log in to the cPanel Control Panel

  1. Open your browser and visit one of the following links to log in to your cPanel:
    • https://domainname/cpanel
    • https://domainname:2083
    • https://cpanel.domainname
    • https://IP_Server:2083
  2. Enter your username and password to complete the login.

NOTE: The domainname Replace it with your actual domain name, e.g. wp12345678.comIf you are logging in using IP, make sure you use your server's IP address. If you are logging in using IP, make sure you use your server IP address.

Step 2: Open the PHP Selector page

  1. In the search field of cPanel, type "PHP", and then select PHP SelectorThe
图片[3]-如何解决 WordPress Fatal Error: Call to undefined function mysql_connect() 的问题
  1. Once on the PHP Selector page, click "extensions"Tab.

Step 3: Enable the required PHP extensions

In "extensions" tab, ensure that one of the following extensions is enabled:

  • mysqli
  • nd_mysqli
  • mysqlnd
  • nd_pdo_mysql
图片[4]-如何解决 WordPress Fatal Error: Call to undefined function mysql_connect() 的问题

If they are not enabled, check the relevant options and save the changes. When finished, you should see a message that it was successfully enabled.

Workaround 3: Change PHP version with MultiPHP Manager

If your cPanel doesn't have a PHP Selector, you can try passing the MultiPHP Manager Change the PHP version:

  1. In the cPanel control panel, search for "MultiPHP Manager".
图片[5]-如何解决 WordPress Fatal Error: Call to undefined function mysql_connect() 的问题
  1. Once on the MultiPHP Manager page, find your domain name.
  2. Change the PHP version to support the ea family (e.g. ea-php74 maybe ea-php81).
图片[6]-如何解决 WordPress Fatal Error: Call to undefined function mysql_connect() 的问题

Solution 4: Check and fix customized server settings

For unmanaged servers, this should be ensured:

  1. The required PHP extensions are installed:sudo apt install php-mysql
  2. Ensure that the correct extensions are loaded in the PHP configuration:
    • compiler php.ini Documentation:sudo nano /etc/php/8.1/cli/php.ini
    • Make sure to include the following lines:extension=mysqli extension=pdo_mysql
    • After saving and exiting, restart PHP:sudo systemctl restart php8.1-fpm
图片[7]-如何解决 WordPress Fatal Error: Call to undefined function mysql_connect() 的问题
  1. Check if the MySQL service is running properly and restart the MySQL service:sudo systemctl restart mysql

Test results

After completing the above steps, try to revisit your website. If the error has been resolved, your site should work properly.

suggestion

If the problem persists:

  • Contact your hosting provider for further assistance.
  • Check the server logs for more detailed error messages.tail -f /var/log/apache2/error.log

By using the above methods, it is possible to solve the Call to undefined function mysql_connect() This ensures that your WordPress website runs smoothly. Supporting the latest PHP versions and extensions is key to improving your site's performance and security.


Contact Us
Can't read the article? Contact us for free answers! Free help for personal, small business sites!
Tel: 020-2206-9892
QQ咨询:1025174874
(iii) E-mail: info@361sale.com
Working hours: Monday to Friday, 9:30-18:30, holidays off
© Reprint statement
Author: xiesong
THE END
If you like it, support it.
kudos7 share (joys, benefits, privileges etc) with others
commentaries sofa-buying

Please log in to post a comment

    No comments