Connecting to my MySQL database in cPanel X

Hi guys I am fairly new to php and i was wondering how to connect to my database using cPanel X.
I can connect to MySQL using local MySQL on my own computer. I need to know how to configure a connection to the server that will be hosting my website and the database where i will be storing data.

The current code i am used to using is:

// server, username, password.
$server = ‘localhost’; // Server
$user = ‘databaseusername’; // Username
$pass = ‘databasepassword’; // Password
$db = ‘databasename’; // Database

//MySQL Connection
if(!mysql_connect("$server","$user","$pass")){
die(mysql_error());
}else{
print 'MySQL connection is good
';
}

//Database Connection
if(!mysql_select_db("$db")){
die(mysql_error());
}else{
print ‘Database connection is good’;
}

//\USE FOR ACTUAL WEB PAGE\//
// server, username, password.
$server = ‘localhost’; // Server
$user = ‘databaseusername’; // Username
$pass = ‘databasepassword’; // Password
$db = ‘databasename’; // Database

mysql_connect("$server", “$user”, “$pass”) or die(mysql_error());
//database
mysql_select_db("$db") or die(mysql_error());
?>

Any help on the situation would be really helpful. Thanks in advance.

Sponsor our Newsletter | Privacy Policy | Terms of Service