Created
February 27, 2017 04:53
-
-
Save kvahuja/cb106063c85265524a6e2ab91da03a2a to your computer and use it in GitHub Desktop.
PHP DB Connect Check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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