Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Using DBI to extract from 2 databases

by scorpio17 (Canon)
on Apr 24, 2013 at 13:18 UTC ( #1030390=note: print w/replies, xml ) Need Help??


in reply to Using DBI to extract from 2 databases

You don't need to explicitly "use DBD::mysql" - DBI will handle that for you.

To help with debugging, wrap all your "prepares" and "executes" with eval, like this:

eval { $sth = $self->dbh->prepare( $sql ); }; if ($@) { die "Database error (prepare): ", $self->dbh->errstr; } eval { $sth->execute(); }; if ($@) { die "Database error (execute): ", $self->dbh->errstr; }

Replies are listed 'Best First'.
Re^2: Using DBI to extract from 2 databases
by Anonymous Monk on Apr 24, 2013 at 13:31 UTC
    What's wrong with DBI's RaiseError?
Re^2: Using DBI to extract from 2 databases
by scorpio17 (Canon) on Apr 24, 2013 at 20:57 UTC

    I'm assuming that RaiseError is on. That causes DBI to "die" if any method results in an error. You use the eval block to trap the error and handle it however you wish. For example, I've found it useful to print out the sql statement if a prepare fails, or the argument list if an execute fails, etc.

    The connect statement should look something like this:

    $dbh = DBI->connect($dsn, $user, $password, {RaiseError => 1, });

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2019-10-16 21:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?