2014-11-01 116 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)