Warning: Trying to access array offset on value of type null in /home/167840.cloudwaysapps.com/bsrvzwpdrx/public_html/wp-content/themes/salma/inc/header/header-default.php on line 3

Fixes For Error in Establishing a Database Connection in WordPress

enquerer > Blog > Uncategorized > Fixes For Error in Establishing a Database Connection in WordPress

Just another hectic day, you rush to your workplace, presses into your seat and mounts your computer. Shockingly enough, when you open up your website in the browser, it shows an error message. ‘WordPress Error Establishing Database Connection’, it says. Not a fair way to start your day!

Why This Error?

The error particularly occurs when WordPress cannot establish a database connection. WordPress makes use of PHP to retrieve information from the MySQL database and sends it to the web browser. This error establishing database connection occurs when the MySQL-PHP connection gets tampered.

There may be various reasons why this happens. Let’s see some of them:

  • The username and password you use may have changed. Not necessary that you changed it. It can also happen accidentally.
  • Heavy traffic spike beyond server capacity can also bring trouble to the website.
  • Poorly coded plugins can also corrupt your database.
  • The web hosting you hired may be faulty and the database may not be functioning at their end properly.

Is The Same Error Repeating in /wp-admin/ Too?

The primary thing to make sure is that if the same error is showing on both front end and backend of the website. If it is showing ‘Error Establishing Database Connection’ at both ends, we can move to the next step. Otherwise, if it is showing ‘One or more database tables are unavailable. The database may need to be repaired’ in the backend, go on and repair your database first.

Just add the following line before the line ‘That’s all, stop editing! Happy blogging’ in wp-config.php.

1 define(‘WP_ALLOW_REPAIR’, true);

Once this repair is finished performing, remember to immediately remove the code from the wp-config.php file. This is because the function is accessible to anyone and everyone as it requires no login.

If the repair didn’t fix the error, you probably had trouble in running the repair function. Worry not! Just follow us below.

Checking Database Login Credentials in WP-Config File

If the previous step didn’t go right, the issue creating the error will be resting in the database settings. The database login settings might turn erratic if you make any changes in the user information or database. This occurs due to lack in proper updating of the wp-config.php file.

wp-config.php being the essential most file in WordPress, it contains all information regarding the WordPress database.

To find the file, navigate to:

Launch Filezilla –> WordPress install folder –> public_html

Open the wp-config.php using any code editor for editing the file.

Once the wp-config.php file is open and available to edit, you can see four essential variables in the code. These variables are required to get the connection to the database. These are:

– Database Name

– Database Username

– Database Password

– Database Host (Localhost or an IP address in most cases)

Always keep in mind that your DB_Host value may not be the same as the localhost. It may vary depending on the host. For most popular hosts like BlueHost, HostGator, GoDaddy, etc., this will be the localhost.

There had been cases where the issue was solved when the localhost was replaced with the IP. Changing the DB_Host value to the IP may easily work if WordPress is running on a local server environment like WAMP or MAMP.

1 define(‘DB_HOST’, ‘’);

The IP’s of every online web hosting service will be different.

If things seem to be good in this file (look around for any typos too), it should be assumed that things have gone wrong at the server end.

Check Your Web Hosting and MySQL Server

Often when your website gets crowded with a lot of traffic, there are chances to get the ‘Error establishing the database connection’. This is because your host server cannot handle the load, especially if you have hired a shared hosting. Although it will be really really slow, the website will mostly show the error message for the majority of users. All you can do is start a live chat with your hosting provider or get them on phone. Just ask them if there are any responsiveness issues regarding your MySQL server.

For checking yourself if the MySQL server is running properly, there are a few things to do. Make a check on the other sites on the same server for any similar issues. If the same error is seen repeated in other sites, there is most probably something wrong with the MySQL server. If no issues are found elsewhere, just go to your cPanel and navigate to the PHPMyAdmin and connect to the database. If you are able to connect, we have to then see if you have got sufficient permissions as a database user. Create a new file with the name ‘testconnection.php’ and input the following code to it.

Always remember to give a new username and password. If the script is successfully connected, it is understood that the user has required permissions, and something else is creating the issue. Now you can return to wp-config.php and rescan for any corrections or typos.

If you are not able to connect to your database with phpMyAdmin, it’s time to know something is wrong with your server. That doesn’t say that the MySQL server is corrupt. The issue may be again of permissions.

This means that the only way to solve things if access gets denied connecting with phpMyAdmin or other similar methods is to get in touch with your hosting provider soon and fix it.

Wrapping Up

We really hope we helped you out to resolve your WordPress ‘Error Establishing Database Connection’ issue. Still, we strongly recommend you to use a managed WordPress hosting, thereby reducing your tension in handling the technical part. Just hand them over to the tech guys. They’ll handle them easily and professionally.

Got to see some other solution for this issue other than what we discussed? Share it with us in the comment box so that we can include them in the blog. Sharing new things always helps.

Warning: Trying to access array offset on value of type null in /home/167840.cloudwaysapps.com/bsrvzwpdrx/public_html/wp-content/themes/salma/template-parts/about_author.php on line 5

Warning: Trying to access array offset on value of type null in /home/167840.cloudwaysapps.com/bsrvzwpdrx/public_html/wp-content/themes/salma/single.php on line 46

Leave a Comment

Warning: Trying to access array offset on value of type null in /home/167840.cloudwaysapps.com/bsrvzwpdrx/public_html/wp-content/themes/salma/single.php on line 62

Warning: Trying to access array offset on value of type null in /home/167840.cloudwaysapps.com/bsrvzwpdrx/public_html/wp-content/themes/salma/inc/template-functions.php on line 133