How to Show All Tables of a MySQL Database Using PHP



PHP







In this article, we show how to show all tables of a MySQL database using PHP.

This way, you can see all tables that have been created for a certain database.

The general MySQL code to make a column a primary key is shown below.





So the above is the MySQL code to show all the tables for a database, where you put the name of the database in place of database_name.

We'll now show how to tie this in with the PHP code to show all tables of a MySQL database.



So, first, we must connect to the database.

After this, we create a $showtables variable which queries the database for all the tables.

After this, we use a while loop to low through all the tables.

We then echo out the table.

Actual PHP Output


CustomerOrders
Customerdata
Customerdata2
DropboxDropboxwoo
EMPLOYEE
Employees
Files
Fruits
How_to_create_a_comment_box_using_PHP_MySQL_and_AJAX
How_to_create_a_website_comment_box_using_PHP_MySQL_and_AJAX
MelissaBreanne
Orders
PHP
PopularToys
Students
Students2334
StudentsDropbox
Toys
UserVideos
Userdata
Usernames
Users
Videos
anything
comments
customers
emails
emails2
engineeringfirm
engineeringfirm2
people
updatetable
uploadprojects
uploadvideos
usercomments
userstate



How to Show Specific Tables

If you have a database full of tables and you're looking for a specific table, you can modify the code.

To find all tables that have a certain word in it, you can use the following code.



To find all the tables that have a certain word in it, all we have to modify the search query, $showtables.

In the example above, we show all tables in the database that have the name 'user' in it.

The percentage signs before and after user means the word user can appear in any part of the string.

Actual PHP Output


usercomments
userstate





Related Resources

How to Create a MySQL Table Using PHP

How to Select a Table from a MySQL Database

How to Check if a MySQL Table Exists Using PHP

How to Show All Tables of a MySQL Database Using PHP

How to Delete a MySQL Table Using PHP

How to Copy a Table Definition in MySQL Using PHP

HTML Comment Box is loading comments...