If you are familiar with how static websites function, you know that all you need is a couple of HTML pages and some pictures and you’re good to go. Unfortunately, it doesn’t always work like that and in many cases, you will need to create and setup a database for your website to run on. Before we get into the actual work of setting up your database, let’s look at why we need databases and how they could actually help us and our site. There are various types of databases around, but in our case, we are only interested in MySQL databases.
Let’s imagine that you are going to be running a forum on your website. The forum itself is not based on one or two static files, but a hundreds of function files. These files work together in showcasing the forum and causing the forum to be a community with such features. All the user information such as usernames, passwords, emails and including all the posts and threads are stored on the database. When you setup a forum, you will be required to setup the database that is going to hold all the user generated content. Databases are used as a means of information storage because it is secure and encrypted, unlike text files with information.
When you are required to setup a database for a particular script, you will begin by accessing your control panel. If you are using cPanel, you will need to navigate to the region where it says “Databases”. Under this row of features, you need to select Databases and wait till the new page loads. One database will require a minimum of one user. So, first create a user for the database and then create the database. To connect the user with the database, scroll down even lower and go into the “Set Privilege” section. On the next screen, select all the privilege options and click OK. You should now have a database with one user.
While creating the user and database, make sure to use very strong passwords. As you don’t always need to login to the database, you can choose something that is extremely uncommon.
If you have a specific database that you are required to upload, you would need to go into the PHP My Admin feature and choose to import a database. Make sure that you are importing the database to the correct database on your hosting account. In order to finish setting up your script, you need to use four pieces of information; the host, database name, user name and password. In most of the cases, your host will be ‘localhost’. The username and database is what you previously setup in the control panel. The password is the password for the database that you created.
If you get database connection errors, there may be an issue with the database function on the server or you may not have properly connected the user to the right database.