in reply to if table exists (DBI)
The correct answer for MySQL (at least as of 5.0).
My criteria for good software:
sub table_exists { my ($dbh, $table, $schema) = @_; unless ($schema) { ($schema) = $dbh->selectrow_array('SELECT DATABASE()'); } my ($exists) = $dbh->selectrow_array( "SELECT COUNT(*) FROM information_schema.tables WHERE table_sc +hema = ? AND table_name = ?", undef, $schema, $table, ); return $exists > 0; }
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
In Section
Seekers of Perl Wisdom