View Full Version : check table?
i would like to make a function like that:
function checktable($table) {
global $DB_site;
if table exists {
event
} else {
other event
}
}what is the best aproach? thanks.
Logician
06-19-2002, 06:17 AM
can be achieved in different ways.. one way would be:
function does_table_exist($tableName)
{
$myquery = "SELECT COUNT(*) FROM $tableName";
$myresult = mysql_query($myquery);
$mynumrows = @mysql_num_rows($myresult);
if($mynumrows)
{return TRUE;}
else
{return FALSE;}
}
if it clashes with vbulletin structure, convert general MYSQL commands to vb MYSQL functions/objects. (Like instead of "mysql_query" use "$DB_site->query_first")
Admin
06-19-2002, 09:04 AM
function table_exists($tblName) {
global $DB_site;
$check = $DB_site->query_first("CHECK TABLE $tblName");
if (!strstr($check['Msg_text'], 'exist')) {
return true;
} else {
return false;
}
}
thanks alot for your help. :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.