Loading

Aceder a BD MySQL via mys

  1. <?php
  2. $dbname = '';
  3. $dbuser = '';
  4. $dbpass = '';
  5. $dbhost = 'localhost';
  6.  
  7. $connect = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die("Unable to Connect to '$dbhost'");
  8.  
  9.  
  10. $test_query = "SHOW TABLES FROM $dbname";
  11. $result = $connect->query($test_query);
  12.  
  13. $tblCnt = 0;
  14. while($tbl = $result->fetch_array()) {
  15.   $tblCnt++;
  16.   echo $tbl[0]."<br />\n";
  17. }
  18.  
  19. if (!$tblCnt) {
  20.   echo "Nao existem tabelas<br />\n";
  21. } else {
  22.   echo "Existem $tblCnt tabelas<br />\n";
  23. }