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

Replace MySQL with MariaDB in cPanel

MariaDB strives to be the logical choice for database professionals looking for a robust,...

cPanel Log file locations

cPanel log file locations and Basic troubleshooting, most activity that happens on a server to...

MySQL downgrade on cPanel server

You know downgrades are not recommended, it’s always best to stick with a newer version and work...

How to repair corrupted mysql database

Sometimes it happens that your database get corrupted due to many reason like it does not get...