使用 PHP/PDO 检查数据库表是否存在 [英] Check if a database table exists using PHP/PDO

查看:21
本文介绍了使用 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 检查数据库表是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆