Check if a database table exists using PHP/PDO

前端 未结 13 1809
长情又很酷
长情又很酷 2020-12-14 16:08

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, SQLi

13条回答
  •  太阳男子
    2020-12-14 16:58

    You might be able to avoid having to rely on an error by using a query along the lines of "SHOW TABLES LIKE 'your_table'" and then counting the rows. I've been using this method successfully with MySQL and PDO but have yet to test it with other DBs

提交回复
热议问题