error in sql statement stops execution

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
caseymanus
Forum Commoner
Posts: 34
Joined: Wed Nov 20, 2002 10:32 pm
Contact:

error in sql statement stops execution

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
caseymanus
Forum Commoner
Posts: 34
Joined: Wed Nov 20, 2002 10:32 pm
Contact:

THANKS!

Post by caseymanus »

Thanks Mac, you the man!
User avatar
Elmseeker
Forum Contributor
Posts: 132
Joined: Sun Dec 22, 2002 5:48 am
Location: Worcester, MA

Post 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? ;)
Last edited by Elmseeker on Fri Jan 10, 2003 5:39 am, edited 1 time in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Her post count :P

Mac

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