-
-
Save BretMishler/5f096411ec213b8288a0961593c22217 to your computer and use it in GitHub Desktop.
Script for a quick PHP MySQL DB connection test.
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-connect-test.php | |
$dbname = 'name'; | |
$dbuser = 'user'; | |
$dbpass = 'pass'; | |
$dbhost = 'host'; | |
$connect = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'"); | |
$connect->select_db($dbname) or die("Could not open the db '$dbname'"); | |
$test_query = "SHOW TABLES FROM $dbname"; | |
$result = $connect->query($test_query); | |
$tblCnt = 0; | |
while($tbl = $result->fetch_array()) { | |
$tblCnt++; | |
#echo $tbl[0]."<br />\n"; | |
} | |
if (!$tblCnt) { | |
echo "There are no tables<br />\n"; | |
} else { | |
echo "There are $tblCnt tables<br />\n"; | |
} |
I think you are mixing procedural and object methods - http://www.w3schools.com/php/php_mysql_select.asp
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The source script used invoked several function calls that were "deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used."