http://www.perlmonks.org?node_id=929809


in reply to DBI fails to return an error code

Only use $DBI::err (and errstr) when connecting to a database.
Use $dbh->err (and $dbh->errstr) for actions performed using this $dbh.
When working with statement handles (like prepared queries), use $sth->err.
Always try to use the err-function in the smallest scope possible, because the rest can be altered by other parts running in your code (in other threads or wherever).