Skip to content

Instantly share code, notes, and snippets.

@jdittmarCodeSnippets
Created April 7, 2013 12:21
Show Gist options
  • Save jdittmarCodeSnippets/5330285 to your computer and use it in GitHub Desktop.
Save jdittmarCodeSnippets/5330285 to your computer and use it in GitHub Desktop.
mysql: table exists
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