mysql 表是否存在

法1:

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

法2:
function TableExists($tablename, $db) {

// Get a list of tables contained within the database.
$result = mysql_list_tables($db);
$rcount = mysql_num_rows($result);

// Check each in list for a match.
for ($i=0;$i<$rcount;$i++) {
if (mysql_tablename($result, $i)==$tablename) return true;
}
return false;
}

上一篇: crontab定时执行   下一篇: squid记录apache日志

提交疑问

请先登录 QQ微博登录

回顶部