If you are logging in to your website as Administrator and you encounter the Error establishing database connection, one of the reasons the error occurred could be one or some of your database tables have been corrupted.
Here are the steps to repair your database:
1. Open the wp-config.php file of your WordPress installation and look for the following line:
/* That's all, stop editing! Happy publishing. */
2. Add the code below right before the line in Step 1:
Have a look at this image:
3. Enter the URL below in your browser:
Do not forget to change example.com to your domain name.
4. Two buttons will be displayed on the page: Repair Database and Repair and Optimize Database. Choose which one to click on.
5. After clicking on one of the buttons in Step 4, you will be given a list of repaired tables as well as an instruction to remove the line in Step 2 from the wp-config.php file. Remove that line.