Last active
April 24, 2018 09:45
-
-
Save appsol/f50619af9b305817c5362d0d231cd037 to your computer and use it in GitHub Desktop.
PHP MySQL Test Connection
This file contains hidden or 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 | |
# Fill our vars and run on cli | |
# $ php -f db-test.php | |
$dbname = 'dbname'; | |
$dbuser = 'dbuser'; | |
$dbpass = 'dbpass'; | |
$dbhost = 'dbhost'; | |
$connect = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'"); | |
mysqli_select_db($connect, $dbname) or die("Could not open the db '$dbname'"); | |
$test_query = "SHOW TABLES FROM $dbname"; | |
$result = mysqli_query($connect, $test_query); | |
$tblCnt = 0; | |
while($tbl = mysqli_fetch_array($result)) { | |
$tblCnt++; | |
#echo $tbl[0]."<br />\n"; | |
} | |
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