-
-
Save Humoud/29643d4fffbbd2668c9a 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 | |
### | |
# NOTE: This code won't work with PHP 7. | |
# MySQL is deprecated and will be removed in PHP 7 checkout MySQLi. | |
### | |
############## JUST FILL THESE VARIABLES ###### | |
$dbname = 'name'; # Name of the Database in the MySQL Server | |
$dbuser = 'user'; # User name of the database in MySQL | |
$dbpass = 'pass'; # Password for the user of in database in MySQL | |
$dbhost = 'host'; # url/link to database | |
################################################ | |
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'"); | |
echo "<p>Connected to MySQL Database Server successfuly.</p>"; | |
mysql_select_db($dbname) or die("Could not open the databse in the MySQL Server '$dbname'"); | |
echo "<p>Selected a Database in the Server successfuly.</p>"; | |
$test_query = "SHOW TABLES FROM $dbname"; | |
echo "<p>Ran Query: SHOW TABLES</p>"; | |
$result = mysql_query($test_query); | |
echo "<p>Printing Results:</p>"; | |
$tblCnt = 0; | |
while($tbl = mysql_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