From b6c0946f37adb4b9df7b84057135c2a5bec3f38e Mon Sep 17 00:00:00 2001 From: mrpete Date: Sun, 4 Mar 2007 15:00:19 +0000 Subject: [PATCH] Add function db_Table_exists() --- e107_handlers/mysql_class.php | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/e107_handlers/mysql_class.php b/e107_handlers/mysql_class.php index cf7146f92..85cdc2558 100644 --- a/e107_handlers/mysql_class.php +++ b/e107_handlers/mysql_class.php @@ -1,10 +1,10 @@ -mySQLaccess); } + + /* + * Verify whether a table exists, without causing an error + * + * @param string $table + * @return string + * + * NOTES: the 'official' way to do this uses SHOW TABLE STATUS, but that is 20x slower! + * LIMIT 0 is 3x slower than LIMIT 1 + */ + function db_Table_exists($table){ + $res = $this->db_Query("SELECT 1 FROM ".MPREFIX.$table." LIMIT 1"); // error if not there + if ($res) return TRUE; + return FALSE; + } + + } ?>