且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查MySQL表是否存在

更新时间:2021-11-03 10:35:04

更新的mysqli版本:

Updated mysqli version:

if ($result = $mysqli->query("SHOW TABLES LIKE '".$table."'")) {
    if($result->num_rows == 1) {
        echo "Table exists";
    }
}
else {
    echo "Table does not exist";
}

原始mysql版本:

if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$table."'"))==1) 
    echo "Table exists";
else echo "Table does not exist";

参考 PHP文档.