How to test access to your database

To test whether you are able to access your database please copy the code below, with your DATABASE NAME, USER and PASSWORD, into Notepad++ and save the file as databasetest.php under /public_html in cPanel.

Then open up a browser window and type yourdomainname.co.nz/databasetest.php
If the connection is successful you will receive a 'Database Connected successfully' message.

If the connection is not successful you will receive a 'Could not connect the database : Username or password incorrect' message. When this happens you must double check your DATABASE NAME, USER and PASSWORD. We recommend you change the password in cPanel first and test again. If still not successful then you must check that you have added the USER to the DATABSE in cPanel with full access rights (all boxes ticked).

<?php
mysql_connect('localhost', 'your_db_user', 'your_db_password') or die('Could not connect the database : Username or password incorrect');
mysql_select_db('your_db_name') or die ('No database found');
echo 'Database Connected successfully';
?>

Remember to delete the databasetest.php file under /public_html
  • test sql database
  • 894 Users Found This Useful
Was this answer helpful?

Related Articles

SQL database backup and restore in phpmyadmin

Backing Up and Restoring a SQL database using PHPMyAdmin Domain Hosting has by default...

SQL database restore in SSH

Follow these instructions if you want to restore a large database through SSH. Often when...

Access MySQL database remotely

If you are having problems remotely accessing your database in your account please make sure...