我想检查我使用 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模板网!
PHP、MySQL PDOException 的死锁异常代码?Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死锁异常代码?)
PHP PDO MySQL 可滚动游标不起作用PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滚动游标不起作用)
PHP PDO ODBC 连接PHP PDO ODBC connection(PHP PDO ODBC 连接)
使用 PDO::FETCH_CLASS 和魔术方法Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔术方法)
php pdo 只从 mysql 获取一个值;等于变量的值php pdo get only one value from mysql; value that equals to variable(php pdo 只从 mysql 获取一个值;等于变量的值)
MSSQL PDO 找不到驱动程序MSSQL PDO could not find driver(MSSQL PDO 找不到驱动程序)