in reply to CGI and DBI, new to me...

dude, put set raiseerror => 1 and use placeholders.. its all described in the doco.

RaiseError:

$dbh = DBI->connect($dsn, $user, $password, { RaiseError => 1, AutoCommit => 0 });

Placeholders:

my $sth = $dbh->prepare(q{ INSERT INTO sales (product_code, qty, price) VALUES (?, ?, ?) }) or die $dbh->errstr; while (<>) { chomp; my ($product_code, $qty, $price) = split /,/; $sth->execute($product_code, $qty, $price) or die $dbh->errstr; } $dbh->commit or die $dbh->errstr;

Both snippets lifed with care from the official doco.

Replies are listed 'Best First'.
Re: Re: CGI and DBI, new to me...
by dga (Hermit) on Dec 13, 2002 at 22:59 UTC
    If you set RaiseError => 1 you don't need all those 'or die's since the dbh will die for you on any error. Wrap the whole thing into an eval and then check $@ afterwards.
    eval { my $sth=$dbh->prepare( q{ your sql here } ); $sth->execute( ... ); # params in the parens to be inserted as above $dbh->commit; }; if($@) { $dbh->rollback; print STDERR "Bad things happened: $@"; }
    The commit line will never get called unless the execute went ok. Your program rolls back the query if the eval died. If you are worried about rollback not working, it should also be wrapped in another eval.