http://qs321.pair.com?node_id=1136641


in reply to if table exists (DBI)

The correct answer for MySQL (at least as of 5.0).
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:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?