How to connect to your MySQL database

Establishing a MySQL database connection is must if you are designing or developing a dynamic website and also if youre doing so in domainking.
It is very important to connect your php script with your MYSQL database by using a specified php code which includes your Database Name, HostDatabase Username and Database Passwordotherwise 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.
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 (********)
ALSO CHECK:  Check if username is already taken after registration in PHP


I am both a front and backend developer

View all posts

Add comment

Your email address will not be published. Required fields are marked * Protection Status