$DBH->do("BEGIN"); # explicitly start a new transaction # this overrides autocommit setting # ... $DBH->do("COMMIT"); #end transaction, this is the "expensive part" ti +mewise
That way seems to be at least unportable, if not wrong. Why don't you follow the usual DBI procedure documented in DBD::mysql, DBD::MariaDB (with nearly exactly the same wording), Transactions of DBI and in begin_work of DBI? At least, manually issuing BEGIN and COMMIT commands bypasses anything DBI knows about transactions.
Try::Tiny from the example in Transactions of DBI can easily be replaced by eval, and using the standard DBI methods works with all DBI-supported databases capable of transactions, not just with MySQL and MariaDB:
my $dbh=DBI->connect('dbi:...', 'user', 'pass', { RaiseError => 1, Aut +oCommit => 1, ... }); $dbh->begin_work(); # if this fails, you have tried to nest transactio +ns. unless ( eval { change_some_stuff($dbh); change_more_stuff($dbh); $dbh->commit(); 1; } ) { warn "Rolling back because: $@"; eval { $dbh->rollback() }; } # At this point, either all changes or no changes have happened in the + database.
Alexander
In reply to Re^2: run 2 query mysql
by afoken
in thread run 2 query mysql
by bigup401
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |