Loading

Aceder a BD MySQL - Teste

  1. <?php
  2.  
  3. $dbname = '';
  4. $dbuser = '';
  5. $dbpass = '';
  6. $dbhost = 'localhost';
  7.  
  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.  
  11. $test_query = "SHOW TABLES FROM $dbname";
  12. $result = mysql_query($test_query);
  13.  
  14. $tblCnt = 0;
  15. while($tbl = mysql_fetch_array($result)) {
  16.   $tblCnt++;
  17.   echo $tbl[0]."<br />\n";
  18. }
  19.  
  20. if (!$tblCnt) {
  21.   echo "Nao existem tabelas<br />\n";
  22. } else {
  23.   echo "Existem $tblCnt tabelas<br />\n";
  24. }