Have you added correct database details in Config file(wp-config). If you added correct config details on your website wp-config.php file, but still your getting same database error connection on the WordPress website every time. This issue related to your database so you need to repair a database onetime then only solve this problem.

For solving “Error Establishing a Database Connection” issue, you need to repair database which you can enable by adding the following code to your WP-config. PHP file

[php]
define( ‘WP_ALLOW_REPAIR’, true );
[/php]