Databases store large amounts of information in an organized format that’s easily accessible through programming languages like PHP. Without a proper connection to an SQL database, a website cannot function and you will likely be met with one of the following warnings:
"Error establishing a database connection" OR "Warning: mysql_connect(): Access denied for user: 'user@localhost' (Using password: YES)"
These warnings indicate that the website can't connect to it's database This can be corrected by checking each of the connection points between the database and the website as detailed in the steps below.
1. Locate the Database Configuration File
The configuration file for the database connections varies with each content management system (CMS). You will need to consult your CMS's documentation to locate which file has the database settings. If you aren't using a CMS, you will need to contact your web developer.
2. Reconfigure the Database Settings
Once the configuration file has been located, you can reconfigure the database settings for your website.
Look in the code for a place where the database name is defined. The database information should be fairly obvious and easy to find. Here is an example of what the database for a WordPress installation would look like:
Make sure that database name, the username and their password are all correct.
Be sure that the host name is localhost.
Save the file, and you are done!
After completing the steps above, you should no longer receive an error message regarding your database connection.