MySQL Forums
Forum List  »  Perl

Error-handling problem using perl DBI with MySQL
Posted by: Sam Wilson
Date: December 16, 2005 06:13AM

Error-handling problem using perl DBI with MySQL..... The truth is that I don't know if this is a MySQL or DBI issue.
Below is my connect string and my insert string. Whenever I run the application with a duplicate entry, the error always gets dumped to the screen as shown below.
Can anyone tell me why the or (||) isn't being activated on the bad insert? How do I capture the error to return an appropriate response to the user?
HELP!
Thanks,
Sam

### connect
$dbh = DBI->connect ("DBI:mysql:host=localhost;database=$db","$dbu", "$dbp",{RaiseError => 1}) ||
die "Connection to:$db failed: $DBI::errstr\n" ;


#### insert
my $sqltxt = "INSERT INTO $insert_table ($insert_columns) VALUES ($insert_values) ";
my $sth = $dbh->prepare($sqltxt)||
die "Could not prepare SQL statement:$sqltxt";

$sth->execute ||
die "Could not execute SQL statement:$sqltxt";
return;
}


##### error dump to screen
Errors Output
DBD::mysql::st execute failed: Duplicate entry 'bert' for key 2 at /line 199. , /usr/perl5/lib/site_perl/5.6.1/Apache/ASP.pm line 1556
Debug Output
DBD::mysql::st execute failed: Duplicate entry 'bert' for key 2 at /line199. , /usr/perl5/lib/site_perl/5.6.1/Apache/ASP.pm line 1556

Options: ReplyQuote


Subject
Written By
Posted
Error-handling problem using perl DBI with MySQL
December 16, 2005 06:13AM


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.