MySQLi表存在 [英] MySQLi Table Exists
本文介绍了MySQLi表存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在PHP中,查看表是否存在的最佳方法是什么?
In PHP, what would be the best way of seeing if a table exists?
这是我到目前为止正在使用的
This is what I am using so far
public function TableExists($table) {
$res = $this->Query("SELECT 1 FROM $table");
if(isset($res->num_rows)) {
return $res->num_rows > 0 ? true : false;
} else return false;
}
推荐答案
如果表不存在,您发布的内容将引发错误.尝试以下方法:
What you posted is going to throw an error if the table doesn't exist. Try this instead:
SHOW TABLES LIKE 'tablename';
并确保您刚返回一行.
这篇关于MySQLi表存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文