2014-11-01 141 views
-2

所有表所以這是現在我的代碼:顯示從MySQL數據庫在PHP

$mysqli = new mysqli("localhost", "username", "password", "dbname"); // connect 

     if (mysqli_connect_errno()) { // checking connection 
      printf("Connect failed: %s\n", mysqli_connect_error()); 
      exit(); 
     } 

所以,有這個數據庫中的幾個表。我想顯示所有表格的全部名稱。我一直在互聯網上搜索一段時間,但我找不到正確的答案。提前致謝!

回答

2

你想要的SQL語句是:

SHOW TABLES; 
1

您可以在PHP代碼中使用這些查詢:

mysql> show databases; 
+--------------------+ 
| Database   | 
+--------------------+ 
| information_schema | 
| begueradj   | 
| mysql    | 
| performance_schema | 
| phpmyadmin   | 
| tester    | 
+--------------------+ 
6 rows in set (0.04 sec) 

mysql> use tester; 
Reading table information for completion of table and column names 
You can turn off this feature to get a quicker startup with -A 

Database changed 
mysql> show tables; 
+------------------+ 
| Tables_in_tester | 
+------------------+ 
| images   | 
+------------------+ 
1 row in set (0.00 sec)