Error to establish a connection to the database in WordPress

When you consult your web page, the hosted code usually makes a connection to the database (hereinafter DB) to know what content should be displayed. This happens with dynamic pages (e.g. PHP), that is, the content is not always the same. Pages whose content does not change are called static pages (e.g. HTML)

Without a connection to the database the code does not have access to the information source to show your web page and usually shows an error message in the browser, for example: Error when establishing a connection with the database, or its variant in English Error Establishing Database Connection.

enter image description here

How do I fix the problem?

To solve the error, verify the connection data to the database. To do this, use a database manager or the PhpMyAdmin and make sure that the user and password are valid and that they can see the database and its tables. If this is the case, then you must modify the corresponding configuration file.

Here is an example of a WordPress "wp-config.php" file. You can edit it with an FTP client (for example Filezilla) and modify the following connection parameters:

define ('DB_NAME', '**database_name_here**'); -> the name of the DB
define ('DB_USER', '**username_here**'); -> the user of the DB
define ('DB_PASSWORD', '**password_here**'); -> the password of the user of DB
define ('DB_HOST', '**localhost**'); -> you can leave it as' localhost'`

Where do I find the parameters in SWPanel?

You can find them by accessing the dashboard of your Hosting service or Cloud service that has DB and click on DB Management.

What can it be?

Normally it is because the password of the user of the database has been modified through the menu DB Management of the SWPanel and the new password has not been defined in the file wp-config.php. However, it can also be due to:

  • The credentials to access your DB are not correct (common error commented in this manual).
  • The DB may have been deleted by accident.
  • Error installing WordPress, or in the migration process.

2024 SW Hosting. All rights reserved. The prices shown on the website do not include any applicable taxes.