Advertisement
easternnl

PHP Mysql Test DB Connection Script

Sep 23rd, 2017
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.62 KB | None | 0 0
  1. <?php
  2. # Fill our vars and run on cli
  3. # $ php -f db-connect-test.php
  4.  
  5. $dbname = 'name';
  6. $dbuser = 'user';
  7. $dbpass = 'pass';
  8. $dbhost = 'host';
  9.  
  10. $link = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
  11. mysqli_select_db($link, $dbname) or die("Could not open the db '$dbname'");
  12.  
  13. $test_query = "SHOW TABLES FROM $dbname";
  14. $result = mysqli_query($link, $test_query);
  15.  
  16. $tblCnt = 0;
  17. while($tbl = mysqli_fetch_array($result)) {
  18.   $tblCnt++;
  19.   #echo $tbl[0]."<br />\n";
  20. }
  21.  
  22. if (!$tblCnt) {
  23.   echo "There are no tables<br />\n";
  24. } else {
  25.   echo "There are $tblCnt tables<br />\n";
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement