Skip to content

Instantly share code, notes, and snippets.

@kvahuja
Created February 27, 2017 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kvahuja/cb106063c85265524a6e2ab91da03a2a to your computer and use it in GitHub Desktop.
Save kvahuja/cb106063c85265524a6e2ab91da03a2a to your computer and use it in GitHub Desktop.
PHP DB Connect Check
<?php
# To run this script use the following command on cli (we assume you have all dependencies installed)
# only checks for mysql for now
# $ php -f db-connect-check.php
$dbhost = 'host';
$dbport = '3306'
$dbname = 'name';
$dbuser = 'user';
$dbpass = 'pass';
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysql_select_db($dbname) or die("Connection to '$dbname' failed.");
$query = "SHOW TABLES FROM $dbname";
$result = mysql_query($query);
$tblCnt = 0;
while($tbl = mysql_fetch_array($result)) {
$tblCnt++;
}
if (!$tblCnt) {
echo "There are no tables<br />\n";
} else {
echo "There are $tblCnt tables<br />\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment