php – 检查MySQL上是否存在表

我正在尝试检查表是否存在,如果存在,则执行一些操作.我继续收到一个错误,告诉我该表不存在而不是完成我的检查.这是代码
$tableExists = $db->prepare("SHOW TABLES LIKE $table_array");
$tableExists->execute();
if($tableExists->rowCount() > 0) {
   // do some code
 } else {
   echo "Unable to add because table does not exists";
}

更新:
根据以下建议,我现在执行以下操作:

$tableExists = $db->prepare("SELECT COLUMN_NAME FROM informatION_SCHEMA.COLUMNS WHERE TABLE_NAME = ?"); 
$tableExists->execute(array($table_array)); 
if(!is_null($tableExist)) { 
    //do something
} else {
    echo "table does not exist;
}

但是,if语句似乎无法确定表是否存在.我还能做什么?

尝试使用information_schema询问表是否存在.就像是
SELECT 
  * 
FROM
  information_schema 
WHERE TABLE_NAME = "$table_array"

看看information_schema所拥有的所有内容,您将对其存储的有关数据库的信息感到惊喜:)

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...