Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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 rifling through the Monastery: (2)
As of 2025-12-08 10:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (87 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.