MySQL Forums
Forum List  »  Perl

Re: Error-handling problem using perl DBI with MySQL
Posted by: bill
Date: January 12, 2006 08:28AM

I think your (||) may be getting over-ridden because you are using the RaiseError=>1 in your connection string.

Try something like the following to handle the error yourself:

$dbh = DBI->connect("$dsn","$dbuser","$dpassword",
{RaiseError=>0,
PrintError=>0,
AutoCommit=>1,
HandleError=>\&dbierrorlog})
or die "Unable to open database:\n\n$DBI::errstr\n";

Note: RaiseError=>0 and HandleError=>\&dbierrorlog.

You can now define a subroutine 'dbierrorlog' to print out your own message when any DBI error occurs.

Later in your code the INSERT error will now be picked up and handled by your 'dbierrorlog' routine in the first instance. Following that you can then also check the return value from your $sth->execute() command which will be 1 if everything was OK, 0 if there was an error, or '0E0' if there was no DBI error but no rows were affected. (In the case of insert this is probably an error as well)

HTH

Bill Stennett

Options: ReplyQuote


Subject
Written By
Posted
Re: Error-handling problem using perl DBI with MySQL
January 12, 2006 08:28AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.