in reply to run 2 query mysql
In general, don't put prepare statements inside of a loop. You can prepare once and use many times.my $updateDeduct = $DBH->prepare("UPDATE USER SET BALANCE = BALANCE - +? WHERE USERNAME = ?"); my $updateAdd = $DBH->prepare("UPDATE USER SET BALANCE = BALANCE + ? W +HERE USERNAME = ?"); $DBH->do("BEGIN"); # explicitly start a new transaction # this overrides autocommit setting $updateDeduct->execute($amount, $user); $updateAdd=>execute($amount, $user); $DBH->do("COMMIT"); #end transaction, this is the "expensive part" ti +mewise
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: run 2 query mysql
by afoken (Chancellor) on Mar 04, 2019 at 18:46 UTC | |
by Marshall (Canon) on Mar 04, 2019 at 20:31 UTC |