Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/PHP/Quick Database Check

March 17, 2017

Quick Database Check

Here’s a quick PHP script to check if your web server can connect to your MySQL database. It’s a neat little script if you don’t have any application installed yet, and you just want to see if your web server setup can quickly connect to the database. All you have to do is create a new file called connect.php, and place the following code inside. Just change the username, password and database. Most likely the hostname will be localhost.

$ sudo nano /var/www/html/connect.php
$username = "user";
$password = "password";
$hostname = "hostname";
$database = "database";
 
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
echo "Successfully Connected to the MySQL Database.<br/>";
 
$selected = mysql_select_db("$dbname", $dbhandle) or die("Could not select database");
echo "Successfully Connected to Database called: $database";

$ sudo nano /var/www/html/connect.php $username = "user"; $password = "password"; $hostname = "hostname"; $database = "database"; $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Successfully Connected to the MySQL Database.<br/>"; $selected = mysql_select_db("$dbname", $dbhandle) or die("Could not select database"); echo "Successfully Connected to Database called: $database";

It’s also available on my Github gist.

Filed Under: PHP Tagged With: connect, mysql

Have content delivered to your mail. Subscribe below.

About Me

I'm Ulysses, Cloud Engineer at Cardinal Health based in Columbus. This blog is about Linux and Cloud technology. When off the grid, I enjoy riding my electric skateboard. I've surfed, snowboarded and played the saxophone in the past. I hope you find this website helpful. It's powered by WordPress and hosted on AWS LightSail.

  • Cloud
  • Linux
  • Git

Copyright © 2012–2021