Check if a database table exists using PHP/PDO

前端 未结 13 1795
长情又很酷
长情又很酷 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:41

    As part of your project, create a schema view.

    For Oracle it would be something like

    SELECT TABLE_NAME FROM ALL_TABLES
    

    For Mysql:

    SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = 'mydbname'
    

    ETC..

    And then run a query in your code against the view.

提交回复
热议问题