PHP PDO检查mySQL数据库中是否存在具有特定名称的表 [英] PHP PDO check if a table with specific name exists in mySQL database

查看:61
本文介绍了PHP PDO检查mySQL数据库中是否存在具有特定名称的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码检查数据库中的表.

The following code checks for tables on the database.

function checkdbexists(){
    global $krdb;
    return $krdb->query("show tables");
}

我们要检查是否存在一个名为'systems'的表,如果存在,则返回1,如果没有,则返回null.

We want to check whether a table called 'systems' exists returning 1 if it does and null or 0 if it does not.

推荐答案

您可以使用

array_search('system',$krb->query('show tables')->fetch())!==false;

这篇关于PHP PDO检查mySQL数据库中是否存在具有特定名称的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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