connectdb.php 640 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. # Fill our vars and run on cli
  3. # $ php -f db-connect-test.php
  4. $dbname = 'testfromphp';
  5. $dbuser = 'testfromphp';
  6. $dbpass = 'NGy5LQwHVdNr0ZLB0NWq7KEVwAJyzhnC';
  7. $dbhost = 'mysqltest';
  8. $connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
  9. mysql_select_db($dbname) or die("Could not open the db '$dbname'");
  10. $test_query = "SHOW TABLES FROM $dbname";
  11. $result = mysql_query($test_query);
  12. $tblCnt = 0;
  13. while($tbl = mysql_fetch_array($result)) {
  14. $tblCnt++;
  15. #echo $tbl[0]."<br />\n";
  16. }
  17. if (!$tblCnt) {
  18. echo "There are no tables<br />\n";
  19. } else {
  20. echo "There are $tblCnt tables<br />\n";
  21. }