Singapore & Australia # 1 for Web Hosting & Domains
SG: +65 6914-7888   AU: 1300-863-436 Asset 1colo Help
Vodien Logo
  1. Home
  2. Knowledge Base
  3. Web Hosting
  4. How to Test MySQL Connection

How to Test MySQL Connection

Note: The steps below is if you’ve already created a database, if you don’t have one yet, please click the guided link on how to create a database.

When you have installed or created your database for your website, you can check the connection using a PHP script. You can create a file called ‘testdb.php‘ or any desired file name and access it with your website.

Here are the steps and script to test your MySQL Connection:

1. Open a notepad or any note editor from your computer.
2. Copy and paste the script below:\

<?php
$servername = “localhost”;
$username = “username”;
$password = “password”;

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
echo “Connected successfully”;
?>

 

Important: Change values for ‘username’ and ‘password’ with your database information. Keep ‘localhost’ as is.

3. Save the file as ‘testdb.php‘ or any desired file name. Upload it to your ‘public_html‘ or the desired directory.
4. Access your website by going to http://yourdomain.com/testdb.php. Or depends on which directory the domain name is pointed to.

You’ll see the message above, if the connection is successful. If it has failed, you’ll be prompted with Connection failed message.

Please don’t hesitate to contact our 24/7 Singapore or Australia Support Team if you have further queries.

(Visited 327 times, 1 visits today)
Updated on October 14, 2020

Was this article helpful?

Related Articles