Click to See Complete Forum and Search --> : MySQL TABLE Exists boolean value


Ultimater
10-30-2005, 10:40 PM
Assuming my Perl program is connected to a MySQL server and a specific database

my $dbh = DBI->connect($dsn,$user,$pass);

How do I test wether a specific Table in that database exists?
I'm in the middle creating some funtionality for the Admin CP. One of the functionalities is to DROP a table if it exists and then recreate the table to make the "auto_increment" start back a 1. How do I test if it exists?

fireartist
10-31-2005, 09:44 AM
You can get an array of tablenames in the current database with

$dbh->tables

An easier way though, might be to just try dropping the table, but wrapping the db call in an eval {} so that the program doesn't die if the table doesn't already exist.