Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. <?php
  2.  
  3. # Fill out the four db vars and run on cli
  4. # $ php -f db-mysql_connect-test.php
  5. $dbname = 'db';
  6. $dbuser = 'user';
  7. $dbpass = '';
  8. $dbhost = 'localhost';
  9. ## end vars
  10.  
  11. $connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
  12. mysql_select_db($dbname) or die("Could not open the db '$dbname'");
  13.  
  14. $test_query = "SHOW TABLES FROM $dbname";
  15. $result = mysql_query($test_query);
  16. $tblCnt = 0;
  17. while($tbl = mysql_fetch_array($result)) {
  18. $tblCnt++;
  19. }
  20.  
  21. if (!$tblCnt) {
  22. echo "There are no tables in $dbname\n";
  23. } else {
  24. echo "There are $tblCnt tables for $dbname\n";
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement