How to connect your website to your MySQL database
Establishing a MySQL database connection is must if you are designing or developing a dynamic website.
It is very important to connect your php script with your MYSQL database by using a specified php code which includes your Database Name, Host, Database Username and Database Password otherwise your queries will be unable to call your database.
When you are uploading/moving your database on the server, the database name and username may be different than your localhost Database usename & password. So it is important to make changes and updates in the code of your php script for your database to work online on the server.
If you have already created a database then you can easily check the name and username of your database in MySQL databases under databases section in your cPanel account.
Also read: If you want to create a new database then you can read how to create a new MySQL Database in your cPanel.
Note: In a Shared Hosting Environment, you can’t change the database username without using the prefix of cPanel username as it by default.
You can use your cPanel username and password for connecting with your MySQL database. But we do not recommend the users to use their cPanel details as their MySQL Database Username & password. This is because if you will ever change your cpanel passwords then this will cause the database connection to stop working. So if you have changed the cPanel password accordingly you should make changes in your MySQL database connection script.
Always use the following database configuration settings:
HOST = localhost
DATABASE NAME = cpanelUsername_databaseName
DATABASE USERNAME = cpanelUsername_databaseUsername
DATABASE PASSWORD = set by you (********)