Created
April 7, 2013 12:21
-
-
Save jdittmarCodeSnippets/5330285 to your computer and use it in GitHub Desktop.
mysql: table exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub does_table_exist { | |
# check wether tables exists in the database | |
my ($dbHandle, $tablename) = @_; | |
eval { $dbHandle->do("select count(*) from $tablename where 1=0") }; | |
if ($dbHandle->err) { | |
# Table does not exist | |
#print "Table $tablename does not exist.\n"; | |
return 0; | |
} | |
else { | |
# Table exists | |
return 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment