List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:May 20 2001 5:05am
Subject:Re: handling failed sql requests in perl
View as plain text  
At 7:54 PM -0700 5/19/01, Cindy wrote:
>OK, let's say you've got the case where you construct an INSERT
>statement to put a new entry into an existing table.  But the
>formatting is wrong (you're short one field in the entry).
>
>What's the code in perl to catch that problem, assuming you've been using
>perl to construct the string and then use the mysql dbi functions to
>interface with mysql?  (See below).
>
>I start it with:
>
>
>$db_handle = DBI->connect('DBI:mysql:database=*****_DB;host=mysql;',
>                          '*****', '********', {RaiseError => 1,
>                          AutoCommit => 1});
>
>I then construct the mysql statement (an insert statement) and call:
>
>$db_handle->do($db_input);

If you want to catch the problem, then you should leave RaiseError
disabled.  Enabling it causes DBI to catch the error itself and
print an error message by calling die().

When you leave RaiseError disabled, you're responsible for checking
for errors, but then you also can catch them:

$db_handle->do($db_input) or handle_error();

>
>Thanks,
>--Cindy
>--
>tittle@stripped
>
>---------------------------------------------------------------------
>Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
>To request this thread, e-mail <mysql-thread74220@stripped>
>To unsubscribe, e-mail <mysql-unsubscribe-paul=snake.net@stripped>
>Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


-- 
Paul DuBois, paul@stripped
Thread
handling failed sql requests in perlCindy20 May
  • Re: handling failed sql requests in perlPaul DuBois20 May