Guest User

Untitled

a guest
Oct 25th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. <?php
  2. # Fill our vars and run on cli
  3. # $ php -f db-connect-test.php
  4. // use define to declare variables
  5. $dbname = 'name';
  6. $dbuser = 'user';
  7. $dbpass = 'pass';
  8. $dbhost = 'host';
  9.  
  10. $connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
  11. mysql_select_db($dbname) or die("Could not open the db '$dbname'");
  12.  
  13. $test_query = "SHOW TABLES FROM $dbname";
  14. $result = mysql_query($test_query);
  15.  
  16. $tblCnt = 0;
  17. while($tbl = mysql_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. }
Add Comment
Please, Sign In to add comment