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

查看:112
本文介绍了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语法, -forward:

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天全站免登陆