-
-
Save M165437/421cd2d23e53a111541a483971f7368b to your computer and use it in GitHub Desktop.
Script for a quick PHP MySQL DB connection test.
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 | |
# Fill our vars and run on cli | |
# $ php -f db-connect-test.php | |
$dbname = 'name'; | |
$dbuser = 'user'; | |
$dbpass = 'pass'; | |
$dbhost = 'host'; | |
$link = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'"); | |
mysqli_select_db($link, $dbname) or die("Could not open the db '$dbname'"); | |
$test_query = "SHOW TABLES FROM $dbname"; | |
$result = mysqli_query($link, $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"; | |
} |
Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you send me the working fix as pull-request, I could include it into the repository and publish an updated version on SF: