PHP is a programming language. In WordPress the core WordPress files – have been written in PHP.
By putting these two together WordPress uses PHP commands to connect to the MySQL database to get the information it needs and later it displays everything on the screen. Now this is where the error comes into play. The error occurs when your WordPress account cannot access to the information in the database via PHP commands. So when that happens WordPress basically does not know what to do next! So the only thing it will display is - “Error establishing a database connection.” Why do we get this type of error while opening the website…? Basically, this error will occur when the website is unable to establish a connection to the database, The reasons are: the database credentials are wrong or it has been changed. It could be that the database server is not responding. it could be that the database has been corrupted. maximum times this problem will occur due to the wrong credentials of the database. Let’s have a look at how to troubleshoot this problem Checking the wp-config.php file Wp-config file is very important for your entire WordPress installation site, In this, you have to mention the valid database details of the WordPress to connect the database. If you change the database credential you have to mention the same details in this file as well. First, you need to check everything is fine in your “web.config” file as mentioned below.MySQL is database technology. And WordPress uses a MySQL database to store all of your website’s content. And this also includes your post, pages with smaller elements like the title of your website, the layout of your widgets, the color settings, etc. Basically, the MySQL database is where every, even the smallest piece of information about your website, is kept.