Andre Andre - 1 year ago 167
PHP Question

Check if a database table exists using PHP/PDO

I want to check if a table with a specific name exists in a database I've connected to using PHP and PDO.

It has to work on all database backends, like MySQL, SQLite, etc.

Answer Source


select 1 from your_table

and then catch the error. If you don't get any error, but resultset with one column containing "1", then the table exists.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download