Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: if table exists (DBI)

by dragonchild (Archbishop)
on Jul 28, 2015 at 17:34 UTC ( [id://1136641]=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1136641]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-16 15:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found