Advertisement
Guest User

Untitled

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