【发布时间】:2013-08-06 18:43:50
【问题描述】:
我正在尝试检查表是否存在,如果存在则执行一些操作。我不断收到一个错误,告诉我该表不存在,而不是完成我的检查。代码如下:
$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 语句似乎无法确定表是否存在。我还能做什么?
【问题讨论】: