本文介紹了使用 PHP/PDO 檢查數據庫表是否存在的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想檢查我使用 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.
它必須適用于所有數據庫后端,如 MySQL、SQLite 等.
It has to work on all database backends, like MySQL, SQLite, etc.
推薦答案
做:
select 1 from your_table
然后捕獲錯誤.如果您沒有收到任何錯誤,但結果集有一列包含1",則該表存在.
and then catch the error. If you don't get any error, but resultset with one column containing "1", then the table exists.
這篇關于使用 PHP/PDO 檢查數據庫表是否存在的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!