How to Connect to the MySQL Database

To work with the database in PHP, you must first connect the script to the MYSQL Database. We will learn in this Tutorial to read data, connect data with the script from a database. But we would like to remind you that PHP should be the intermediary between you and MySQL.  Indeed, MySQL first request a user name and password. PHP establishes a connection to MySQL. Once the connection is established, you can do all the things you want in your database!

Configuration Settings

Database supportive scripts, such as Wordpress, Joomla, Drupal, WHMCS will normally have a system generated default configuration file ready for you to edit with the appropriate information.

Below you can view the Demo of Config access information which will look like:

Host Name = localhost
Database Name = cpUsername_dbName
Database Username = cpanelUsername_databaseUsername
Database Password = whatever you selected


WordPress Example


Username = loe0034    Database Name = wrdp1
Database-Username = wp1    Database-User Password = sfggs7%Pxa9
// ** MySQL Settings ** //
/** The name of the database for WordPress */
define('DB_NAME', ' loe0034_wrdp1');

/** MySQL database username */
define('DB_USER', ' loe0034_wp1');

/** MySQL database password */
define('DB_PASSWORD', ‘sfggs7%Pxa9');

/** MySQL hostname */
define('DB_HOST', 'localhost');

At the same time as it is possible to connect to the database just by using your cPanel username and password, we NEVER would like to suggest this. Every time you must change or reset your cPanel password & simultaneously change the database password. You must also change config password too after changing database password otherwise databases will stop working until configuration files are updated.



Tips for Migrating Databases

Whenever you move your databases to RepriseHosting servers, the database name and username may change. This change should be changed in your script code.  On Linux Shared servers, Database username can’t be altered to any other usernames without the presence of cPanel username in it. This is required to keep your database usernames unique from others so that it will not conflict with others on the server.


  • 7 کاربر این را مفید یافتند
آیا این پاسخ به شما کمک کرد؟

Related Articles

How to Enable cPHulk Brute Force Protection on Your Dedicated or VPS Server

You may wonder why you need cPHulk Brute Force Protection. The answer is simple, it provides...

Where to upload files for an addon domain?

As you set up your Addon domain, the system will create a folder for you. By default, the folder...

How to Connect to the MySQL Database Remotely

Enabling Remote MySQL connectivity is often done to enable a program on your laptop or computer...

How to import your MySQL database

How can I import a database? Firstly, Login to Cpanel Simply, Go to phpMyAdmin Click...

What Are Cron Jobs?

A cron job is a A linux based command for arranging a control or program on your server to finish...