我正在尝试检查表是否存在,如果存在,则执行一些操作.我继续收到一个错误,告诉我该表不存在而不是完成我的检查.这是代码:
$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"
原文地址:https://www.jb51.cc/php/134889.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。