in reply to correct way to do multi-insert/update transaction
You might also benefit from a read through Basic debugging checklist. In the end, your code might look something closer to
#!/usr/bin/perl use DBI; use strict; use warnings; use diagnostics; # create database connection my $dbh = DBI->connect("DBI:mysql:database=somedb;host=localhost", "user", "pass", { 'RaiseError' => 1, 'AutoCommit' => 0, }, ); # trap errors using eval{} my $insert_sth = $dbh->prepare("insert into table (field) values(?)"); eval { #go around some loop to get a value for (1...100000) { $insert_sth->execute($_); } # commit changes $dbh->commit(); }; # any errors # rollback if ($@) { print "Transaction aborted: $@"; $dbh->rollback(); } # close connection $dbh->disconnect();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: correct way to do multi-insert/update transaction
by Anonymous Monk on Apr 28, 2011 at 13:40 UTC | |
by kennethk (Abbot) on Apr 28, 2011 at 13:47 UTC |