daily pastebin goal
10%
SHARE
TWEET

Untitled

a guest Dec 6th, 2016 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top