Page 1 of 1

error in sql statement stops execution

Posted: Thu Jan 09, 2003 10:12 am
by caseymanus
All,

I am trying to process inside a loop a large amount of insert statements. This is not difficult, but if one of them fails due to a data problem causing a syntax error, the entire script stops executing. I dont want that, I want to log the bad statement and continue execution....
something like a try-catch block. This is what I am doing now....

Code: Select all

odbc_exec ( $db, $sqlstm) or die ("ERROR MESSAGE OR LOGGING FUNCTION")
So even with the or die it stops...is there any other kind of error handling or a setting in PHP.INI that would make it continue?

Posted: Thu Jan 09, 2003 10:21 am
by twigletmac
Using or die will kill the script if an error is encountered. Instead you could do something like the following (untested) code:

Code: Select all

@$result = odbc_exec($db, $sqlstm);
if (!$result) { // if it doesn't work
    ERROR MESSAGE OR LOGGING FUNCTION
}
Mac

THANKS!

Posted: Thu Jan 09, 2003 10:40 am
by caseymanus
Thanks Mac, you the man!

Posted: Thu Jan 09, 2003 10:45 am
by Elmseeker
You've been a member for 2 months and you're justfiguring this out now? :) We know Mac is "Da WOman!", Seen HER post count lately? lol
:twisted:

[Edit]
Sorry Mac, is that better? ;)

Posted: Fri Jan 10, 2003 2:40 am
by twigletmac
Her post count :P

Mac

Edit: :lol: Elmseeker, ok I feel better now :lol: