Fixing the Error Establishing a Database Connection Message

Fix ebsite error establishing a database connection

Table of Contents

Where is the “Error Establishing a Database Connection” Message is Coming From?

The database connection error is seen by both web developers when working on website code, but also by end users on a web page.   So I am going to address it from both perspectives.

Error Establishing A Database Connection

What does Error Establishing a Database connection mean?

It’s literally just what it says.  A connection is broken.  The website code has to connect to the database to communicate with it. In simple terms, code and databases “talk” to each other in order for code to be able to display content on a web page (and do a myriad of other things).

Think of it like a call on mobile phone. If you are talking to someone and the connection is dropped, you can no longer communicate.

Without an established database connection, the website is going to show database errors until it is reconnected.

Typically this means EVERY web page on your site will be down because database driven websites almost always connect to the database on every single page.

So while some errors are quite cryptic, i.e  500 Internal Server Error, this database error gives you a good clue as to what is going on.

This type of error is known as a fatal code error because the website won’t function without it.

What can a user do about the error?

As mentioned above, the source of this error comes from the website code not being able to connect to the database to be able to display web pages.   Even though the error will show in your web browser, it is not related to your browser. It does not matter if you are using Google Chrome, Safari, Firefox or Edge. The error comes from the website you are viewing. A user can not fix this problem.

Sometimes a database connection error is intermittent. A user will reload the web page and then it may load. They may think they fixed the problem, but it is coincidence that the page reload appears to have an affect on it. 

Related Post:   Monthly WordPress Maintenance Services - Is it worth it?

Debugging this error can be tricky if you don’t know what to look for.

Any database driven website can generate this error, so from a developers perspective you need to consider the following:

  • It’s not due to the type of CMS you are using.  So you won’t see an error establishing a database connection in WordPress any more than you would see it on a Joomla, Drupal or any other type of open source or commercial content management system software.
  • Database connection errors are not specific to your web host.  While cheap, low budget, shared hosting service can be a common source of this error due to server performance issues, the error can occur on any web host. (This error can be code related or server related)
  • If you are using a local server environment with MAMP, XAMPP, WAMP – there could be a configuration error you need to resolve, but it’s not specific to this setup and can be easily fixed.

Error establishing a database connection on GoDaddy

I am using GoDaddy as and example because it is a popular shared hosting option, but it does not matter who the host is. GoDaddy, Hostgator or Bluehost, Network Solutions all can generate the same error.

Inexperienced web developers or DIY website owners may start debugging this problem by submitting a trouble ticket to their web hosting support.  They will tell you one of two things.

  1. They are having issues with the database and “are working on it”.
  2. It’s not their problem, it’s your website code.

If the source of the problem is the web host, your hands are tied. There is nothing you can do on shared web hosting services. You have to wait for them to resolve the problem.

If they tell you it is the website code, then it is your problem to fix, and hosting support will not/should not fix it. (  A bit of advice, – NEVER give your web hosting support permission to modify your code. If they do it without asking first, find a new host.)

Related Post:   Google's New Google For Jobs Initiative

How do you fix the error establishing a database connection when it is a code issue?

The majority of time the source of this database error is due to incorrect login details.

In order to connect your code to a database, you need to tell it:

  • database name
  • database username
  • database password
  • database server

This is typically stored in a configuration file. Depending on how your site is coded this could be in different places.

WordPress error establishing a database connection

Because WordPress is so popular, I’m going into specific details of where to look.

Within WordPress, the database connection details are stored in the wp-config file located in the top level directory that WordPress was installed. Typically this will be in a directory called  public_html.

Depending on your web hosting configuration though, this can sometimes be complicated to find.

FTP wp-config.php to your computer and look for these lines of code.

define( 'DB_NAME', XXXX);
define( 'DB_USER', XXXX);
define( 'DB_PASSWORD', XXXX);

Note the database name and user name.
Now log in to your hosting control panel. (Most common is cPanel. On shared hosts that have a proprietary dashboard , you may see this under Advanced Settings.)

Click on the MySQL database icon
Find the database user and reset the password.
Copy the new password and paste it into your wp-config file.
FTP the file back to your server.

Reload the page.

If you don’t know what FTP is,  then outsource to a PHP programmer to debug and fix this error for you.

Other Reasons

Other reasons could be a corrupt database, or your host has made upgrades/changes that require code updates.

If you need help troubleshooting this website error, or want to hire me to fix your website, get in touch. I’ve have extensive experience with troubleshooting web based databases. I handle all types of website repair and can have your site back online in no time.

Facebook
Twitter
LinkedIn
Pinterest

More Advice

Free Estimate

Do you need help with your website?

Get answers to your questions about hiring a web developer online to outsource website development, WordPress, maintenance and website support.

Do NOT follow