MySQL检查表是否存在而不抛出异常 [英] MySQL check if a table exists without throwing an exception

查看:37
本文介绍了MySQL检查表是否存在而不抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在不抛出异常的情况下检查 MySQL 中是否存在表(最好通过 PHP 中的 PDO)的最佳方法是什么.我不想解析SHOW TABLES LIKE"等的结果.一定有某种布尔查询吗?

What is the best way to check if a table exists in MySQL (preferably via PDO in PHP) without throwing an exception. I do not feel like parsing the results of "SHOW TABLES LIKE" et cetera. There must be some sort of boolean query?

推荐答案

我不知道它的 PDO 语法,但这看起来很简单:

I don't know the PDO syntax for it, but this seems pretty straight-forward:

$result = mysql_query("SHOW TABLES LIKE 'myTable'");
$tableExists = mysql_num_rows($result) > 0;

这篇关于MySQL检查表是否存在而不抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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