Xavvey
Xavvey

Reputation: 43

PHP/SQL - Check if a DB has any tables or not

How do I check if a created database has any tables added to it yet? I'm not looking for values inside a table but just tables in general.

Is there an equivalent to 'SELECT 1 FROM db_table' kind of query or is there a php function that can check if any tables exist in a database?

What I want to achieve is something along the lines of:

if(db_doesn't_have_tables) { show message }
else { do something }

Upvotes: 0

Views: 46

Answers (2)

Stu
Stu

Reputation: 32619

Most databases support the INFORMATION_SCHEMA catalog views:

select * 
from INFORMATION_SCHEMA.TABLES
where TABLE_TYPE='BASE TABLE'

However all platforms will have better vendor-specific system tables for the purpose.

Upvotes: 0

HighestDreams
HighestDreams

Reputation: 28

I hope this helps you :

SHOW TABLES FROM database

Upvotes: 1

Related Questions