Nowadays, the use of a database is very common when building a website. The main role of the database is to store the information that is present on each page. This allows you to modify your design without affecting the text that is shown throughout your site. As such, it is recommended that all new websites take full advantage of the benefits, afforded by the use of a database. In this article, you will learn how to find your database connection settings, so you can hook up your site to a database. Additionally, you will learn how to manipulate the data contained within the database itself.

What Is the Database Manager?

In the Hosting Control Panel, you will find a section dedicated to the management of your databases, aptly named the Database Manager.

You can manage your MySQL and PostgreSQL databases through the dedicated Database Manager section of the Hosting Control Panel.
You can manage your MySQL and PostgreSQL databases through the dedicated Database Manager section of the Hosting Control Panel.

Through the Database Manager, you are able to create, edit, and delete databases. There are two supported database types – MySQL and PostgreSQL. Both database types can be used to store your site’s content and you can interact with each database type in a similar manner. You can learn more about the features and capabilities of this section of our Control Panel by reading our in-depth tutorial on the Database Manager.

We believe that having a database is a fundamental part of running a modern website and that is why even our free hosting plan comes with one MySQL database which you can use. If you require multiple databases or you wish to use a PostgreSQL database, you may consider opting for one of our premium hosting packages.

Where Can I Find My Database Connection Settings?

Locating your database connection settings is a straightforward process:

  1. Open the Database Manager section of the Control Panel.
  2. Click on the Options button next to your database. If you haven’t created a database yet, you can do so by using the database creation form in the upper half of the Database Manager interface.
  3. You will notice that several tabs appear beneath the database name. Click on the Information tab.
The Information tab for your database contains all of the information needed to connect to it.
The Information tab for your database contains all of the information needed to connect to it.

You will then be presented with your database connection settings. This information includes the:

  • Database Host
  • Database Port
  • Database Name
  • Database User
  • Database Password
  • Database Version
  • Database Storage Engine

Note: Unlike other hosting providers, here at AwardSpace we use dedicated database servers in order to better distribute the server load and offer faster loading times for your website. As such, you need to find your database host using the information provided in the Information tab. Using localhost will not allow you to establish a successful connection to our database server.

Where Can I Get a Sample PHP Script That Connects to My Database?

You are welcome to use the following PHP script as the starting point for your website. This script opens a connection to your MySQL database, lists the names of all tables that are currently stored, and then closes the connection:

<?php

$db_host='DB_HOST'; //Should contain the "Database Host" value
$db_name='DB_USER'; //Should contain the "Database Name" value
$db_user='DB_NAME'; //Should contain the "Database User" value
$db_pass='DB_PASS'; //Should contain the "Database Password" value

$mysqli_connection = new MySQLi($db_host, $db_user, $db_pass, $db_name);

if ($mysqli_connection->connect_error) {
echo "Could not connect to $db_user, error: " . $mysqli_connection->connect_error;
} else {
echo "Connected to $db_user! <hr> The database contains the following tables: <br />";
}

$showtablequery = "SHOW TABLES FROM $db_user";
$showtablequery_result = mysqli_query($mysqli_connection, $showtablequery);

while($showtablerow = mysqli_fetch_array($showtablequery_result))
{
echo $showtablerow[0]."<br />";
}

$mysqli_connection->close();
echo "<hr> mysqli_connection closed!";

?>

For the best results, create a new .PHP file in your hosting space and copy the sample code above. Just make sure to updates the values for the $db_host, $db_name, $db_user, and $db_pass variables. They are defined at the very beginning of the script. Once your credentials are entered and saved, you should be able to run your script by opening it in a web browser. The end result should be a page which lists all tables present in your MySQL database: