Test MySQL database connection with php script

You can use the following php script which is used to test mysql database connection on your cpanel server.

<?php
$link = mysql_connect('db_host', 'db_username', 'db_password');
if (!$link)
{
die('Could not connect the database: ' . mysql_error());
}
echo 'Database Connected successfully';
mysql_close($link);
?>

db_host : Mostly used ‘localhost’ when you connect on the same server.

db_username : Use your test database username.

db_password : Use your test database password.

The above MySQL connection test script is using mysql_connect(); function which is designed to open a connection to a MySQL Server.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

cPHulk Brute Force Protection

WHM/cPanel has a service, protected from Brute Force attack, which is called “cPHulk Brute Force...

Enable SSH key authorized login without root password

You need to generate SSH Key ( the private key )on your cpanel server and then update remote...

How can I Redirect URLs in cPanel

Login your cpanel 1. Click the Redirects button on the front page under the “domains” 2. Enter...

Enable Custom php.ini for Fast CGI

With fast-cgi, custom php.ini needs to be in the cgi-bin folder. 1) Move php.ini to cgi-bin...

ConfigServer Firewall CSF installation

ConfigServer firewall is a popular linux firewall security suite. It is easy to install, flexible...

Powered by WHMCompleteSolution