How to check your MySQL database connection is working

#1

Introduction

Starting off your CMS based website can be tricky if you encounter database connection errors, such as Error establishing a database connection. In this tutorial, we will teach you how to check your database’s connection, as well as resolve any database connection errors related to incorrect credentials.

What you’ll need

Before you begin this guide you’ll need the following:

  • Access to your 000webhost members area.
  • An uploaded website at 000webhost that uses databases.

Step 1 — Finding your database credentials at 000webhost

Firstly, login to your 000webhost members area at the 000webhost login page.

Once inside, find and open the Manage Database section, which is located at the top of your page in the 000webhost menu:

You will see a list of your currently created databases. If one does not yet exist, please create it, along with a database user and password.

If your database name or username is too long and is not fully shown, please simply click anywhere on the database name and it will be fully displayed to you.

There are four main points of interest:

  • DB Name: Your database’s name.
  • DB User: The database’s privileged user. This username is used when authenticating the connection to your database.
  • DB Host: The hostname of the MySQL server which houses your database. This is usually localhost.
  • DB User Password: The password of the database’s privileged user. This password should be comprised of lowercase and uppercase latin alphabet letters and numbers only. You should never use special characters, such as “(>@!;” or others, they do not make your password more secure and can cause database connection errors.

All of these settings are set when your database is created. If you have forgotten the password for the user, please change it right now using the Change password tool and write it down on your computer for use in next step. Keep the database information screen open, we will need it for the next step.

Step 2 — Verifying database connection credentials inside your website’s configuration script

Now that we know your 000webhost account’s system side database credentials, we simply need to cross reference them with your website’s configuration file. To do this, we will have to find the file by using 000webhost’s File Manager.

IMPORTANT! - keep the database information screen open. In a new tab, open the Upload Files tool at the top of your 000webhost menu, and then click Upload files to access the File manager:

Once inside, we need to navigate through the File Manager and find your website’s configuration file. In our example, we are using Wordpress, and the location of our configuration file is /public_html/wp-config.php. Different CMS systems or websites have different configuration files. Here are a few most popular ones:

  • Wordpress: /public_html/wp-config.php
  • Joomla: /public_html/configuration.php
  • Drupal: /public_html/sites/default/settings.php

If you are using another system, you can simply Google the location of the file, i.e. search Google for “prestashop database configuration file location”. If you have a custom-built website, we recommend contacting your website’s developer for specific file locations.

Moving on with our example, simply open the public_html directory in the file manager by using the navigation bar on the left side:

With this directory now open, we will see a listing of files inside this directory on the right side. Right click the wp-config.php file and click Edit:

The file will then be opened via the 000webhost file editor. Scroll down through the file until you come across MySQL configuration details. This is usually indicated by the script, however, if it is not, you should just skim across the file until you find something related to database hostnames, database names, etc. The exact location depends on the type of script. In our Wordpress example, it looks like this:

Now that we can see the database information on one tab of our browser, and we are editing the configuration details on another, we can kill two birds with one stone - verify the connection, and fix any errors that may be present.

Simply open the browser tab where you checked out your database connection credentials and copy each field into the configuration file that you are editing. For example, if you are copying the DB Name field, replace the old value between the apostrophes in the script’s DB_NAME field. Here are the same screenshots again to illustrate what it should look like:

Make sure to also replace the password in the configuration file to the one you wrote down previously. If you did not write it down or forgot it, simply change it once again and then input the new password that you changed into the configuration file’s DB_PASSWORD field. We recommend copy-pasting every time, this will help avoid mistakes. Also, make sure there are no empty spaces in front and at the end of the fields.

Once you have verified all fields, simply click Edit and your changes will be saved. All that remains is to check whether our website is operational again!

Conclusion

We learned how to verify database connection details, as well as how to fix any errors related to database connection credentials in one go. If you are still receiving database connection details and have performed the steps above, it is likely that there are other coding errors inside your website that may need fixing. We recommend searching the software developer’s website for possible solutions or checking out other Hostinger tutorials.

Connect To database via php
How to find DB Host?
How to connect to db from 000webhost - help
Mysql Hostname confused in getting
MY SQL Help
Connection to Database doesn't work
Access denied for user 'username'@'localhost' (using password: YES)
How to know my db host?
Blank PHP display
Access denied for user 'username'@'localhost' (using password: YES)
Access denied for user 'axxxxxxx'@'localhost' (using password: NO)