Create a gist now

Instantly share code, notes, and snippets.

Script for a quick PHP MySQL DB connection test.
# Fill our vars and run on cli
# $ php -f db-connect-test.php
$dbname = 'name';
$dbuser = 'user';
$dbpass = 'pass';
$dbhost = 'host';
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysql_select_db($dbname) or die("Could not open the db '$dbname'");
$test_query = "SHOW TABLES FROM $dbname";
$result = mysql_query($test_query);
$tblCnt = 0;
while($tbl = mysql_fetch_array($result)) {
#echo $tbl[0]."<br />\n";
if (!$tblCnt) {
echo "There are no tables<br />\n";
} else {
echo "There are $tblCnt tables<br />\n";

Says no tables when there are some.

aeroson commented Sep 13, 2015

thank you




That really worked perfect and it is fantastic! I tried so many scripts, and that worked excellent. Many thanks.


Great! Obrigado!




great for fast implementation


I forked this to make some edits to deal with deprecated functions but I'm not sure how to push it back to yours for approval if you so choose to commit the changes.


thank you! works great.

omalave commented Jun 13, 2016

mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead


gives me 403 error


Nice. Simple, useful, direct and to the point. Thanks!


Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /var/www/html/car/db-connect-test.php:10 Stack trace: #0 {main} thrown in /var/www/html/car/db-connect-test.php on line 10


500 error. what missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment