Php 如何使用pdo检查表是否存在

Php 如何使用pdo检查表是否存在,php,mysql,Php,Mysql,可能重复: 基本上我有MySQL dbname=test和table name=page 我想使用php PDO创建一个查询,以检查我的db“test”中是否存在表“page” 我试过了,但不管用。。它总是告诉我它不存在。。即使是这样 if (array_search('pages',$db->query('show tables')->fetch()) !== false) { echo "the db exists"; } else { echo "the db do

可能重复:

基本上我有MySQL dbname=test和table name=page

我想使用php PDO创建一个查询,以检查我的db“test”中是否存在表“page”

我试过了,但不管用。。它总是告诉我它不存在。。即使是这样

if (array_search('pages',$db->query('show tables')->fetch()) !== false) { echo "the db exists";

    } else { echo "the db doesnt exists";
    // Create tableS
    //$IDB->execute();
    }

PDO中的现有表没有预定义的测试,您必须执行以下操作:

$pdo = new PDO($dsn,$user,$pass,$options);
$results = $pdo->query('SHOW TABLE LIKE \'page\'');
if(count($results)>0){echo 'table exists';}

你做了哪些研究来帮助你找到答案?首先,链接没有显示pdo。。。然后我研究了put,我没有得到“从信息中选择用户\u SCHEMA.TABLES,其中table\u SCHEMA='db\u name'”示例。。。这就是为什么我希望有人告诉我……没问题:我试过了,但它总是返回它存在的$r1=$db->query('SHOW TABLES LIKE'subjects\'');如果(计数($r1)>0){echo“表存在”}否则{echo“表不存在”;//创建表}