ISPA Winner 2018 16 Years of Krystal

Web Hosting

Please find below our list of Web Hosting guides to help with your hosting account.

How to connect to a MySQL database using PHP

This article was posted in: Web Hosting

The hostname to use when connecting to one of your cPanel MySQL databases from a web script running within the same cPanel account is localhost.

As a quick guide, you can use the following PHP code to make a connection.

$hostname = "localhost"; // mysql hostname - always use localhost
$database = "databasename"; // substitute your mysql database name
$username = "username"; // substitute your mysql user name
$password = "somethinghardtoguess"; // your mysql users's password
$con = mysqli_connect($hostname, $username, $password) or die(mysql_error()); // make connection to mysql