Programming Tips - How do I know what went wrong with my SQL query?

Date: 2008jun19 Language: perl Library: DBI Q. How do I know what went wrong with my SQL query? A. Perl's DBI has *three* function for you:
$number = $dbh->err(); # Gets the error number $str = $dbh->errstr(); # In english $str = $dbh->state(); # SQL 5 character code
Notice that they require a handle so what to do when a connect() fails and you don't get a handle? In that case use:
$number = DBI::err(); # Gets the error number $str = DBI::errstr(); # In english $str = DBI::state(); # SQL 5 character code