I believe that this is pretty clear in the DBI man page. Just remember that if you have a connection problem, you won't have a db handle (i.e., $dbh) so you should use $DBI::errstr as per the docs:
"connect" $dbh = DBI->connect($data_source, $username, $password) or die $DBI::errstr; $dbh = DBI->connect($data_source, $username, $password, \%attr) or die $DBI::errstr; Where you're already working with a DB handle, use it to get the relevant errors: $rows = $dbh->do($statement) or die $dbh->errstr; $sth = $dbh->prepare($statement) or die $dbh->errstr; $rc = $dbh->commit or die $dbh->errstr; $rc = $dbh->rollback or die $dbh->errstr; Etc....per the docs. Eric > -----Original Message----- > From: E R [mailto:pc88m...@gmail.com] > Sent: Thursday, July 07, 2011 2:27 PM > To: dbi-users@perl.org > Subject: any issues with $DBI::err not getting cleared on a ->connect > call? > > I'm working with some legacy perl code, and there is a lot of checking > of $DBI::err after a ->connect call: > > # DBI bug workaround > my $previous_error = $DBI::err; > my $previous_error_str = $DBI::errstr; > eval { > $dbh = DBI->connect(..., { AutoCommit => 1, RaiseError => 1, > PrintError => 0, LongReadLen => ..., LongTruncOk => 1 }); > if ($dbh && ($dbh->err || $dbh->errstr) && ($dbh->err eq > $previous_error || $dbh->errstr eq $previous_error_str) { > $dbh->set_err(undef, undef); > } > }; > if (!$dbh || $@ || $DBI::err) { > # something bad happened > } > > Is any of this still necessary? Can I safely replace it with: > > eval { > $dbh = DBI->connect(...); > }; > if (!$dbh || $@) { > # something bad happened > } > > It seems that at one point there were issues with $DBI::err not getting > cleared. _______________________________________________ This e-mail may contain information that is confidential, privileged or otherwise protected from disclosure. If you are not an intended recipient of this e-mail, do not duplicate or redistribute it by any means. Please delete it and any attachments and notify the sender that you have received it in error. Unless specifically indicated, this e-mail is not an offer to buy or sell or a solicitation to buy or sell any securities, investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Barclays. Any views or opinions presented are solely those of the author and do not necessarily represent those of Barclays. This e-mail is subject to terms available at the following link: www.barcap.com/emaildisclaimer. By messaging with Barclays you consent to the foregoing. Barclays Capital is the investment banking division of Barclays Bank PLC, a company registered in England (number 1026167) with its registered office at 1 Churchill Place, London, E14 5HP. This email may relate to or be sent from other members of the Barclays Group. _______________________________________________