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() 的问题](https://www.361sale.com/wp-content/uploads/2025/01/20250119100918661-image.png)
Root causes of the problem
The main reasons for this error include:
- The database service is not running or is misconfigured.
- Extensions related to database interaction are not enabled in the PHP environment, such as the
mysqli
The - PHP Newer versionNo longer supported
mysql_connect
function. - 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() 的问题](https://www.361sale.com/wp-content/uploads/2025/01/20250119100254265-image.png)
- 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
- 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
- Enter your username and password to complete the login.
NOTE: The domainname
Replace it with your actual domain name, e.g. wp12345678.com
If 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
- In the search field of cPanel, type "
PHP
", and then select PHP SelectorThe
![图片[3]-如何解决 WordPress Fatal Error: Call to undefined function mysql_connect() 的问题](https://www.361sale.com/wp-content/uploads/2025/01/20250119100758778-image.png)
- 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() 的问题](https://www.361sale.com/wp-content/uploads/2025/01/20250119100826827-image.png)
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:
- In the cPanel control panel, search for "MultiPHP Manager".
![图片[5]-如何解决 WordPress Fatal Error: Call to undefined function mysql_connect() 的问题](https://www.361sale.com/wp-content/uploads/2025/01/20250119101007705-1737252590939.png)
- Once on the MultiPHP Manager page, find your domain name.
- Change the PHP version to support the ea family (e.g.
ea-php74
maybeea-php81
).
![图片[6]-如何解决 WordPress Fatal Error: Call to undefined function mysql_connect() 的问题](https://www.361sale.com/wp-content/uploads/2025/01/20250119101224279-1737252739738.png)
Solution 4: Check and fix customized server settings
For unmanaged servers, this should be ensured:
- The required PHP extensions are installed:
sudo apt install php-mysql
- 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
- compiler
![图片[7]-如何解决 WordPress Fatal Error: Call to undefined function mysql_connect() 的问题](https://www.361sale.com/wp-content/uploads/2025/01/20250119155651602-image.png)
- 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.
Link to this article:https://www.361sale.com/en/31429The article is copyrighted and must be reproduced with attribution.
No comments