learn php, learn jquery, learn asp.net, learn javascript, learn html, learn css, learn xml, learn ruby on rails, learn python
Showing posts with label sql. Show all posts
Showing posts with label sql. Show all posts
Thursday, February 12, 2015
Tuesday, June 25, 2013
Mysql Transactions
Mysql Transactions
Avoid inconsistency in the cases where the script terminates unexpectedly.
try {
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->beginTransaction();
$dbh->exec("insert into staff (id, first, last) values (23, 'Joe', 'Bloggs')");
$dbh->exec("insert into salarychange (id, amount, changedate)
values (23, 50000, NOW())");
$dbh->commit();
} catch (Exception $e) {
$dbh->rollBack(); // roll back if error occured
echo "Failed: " . $e->getMessage();
}
Avoid inconsistency in the cases where the script terminates unexpectedly.
try {
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->beginTransaction();
$dbh->exec("insert into staff (id, first, last) values (23, 'Joe', 'Bloggs')");
$dbh->exec("insert into salarychange (id, amount, changedate)
values (23, 50000, NOW())");
$dbh->commit();
} catch (Exception $e) {
$dbh->rollBack(); // roll back if error occured
echo "Failed: " . $e->getMessage();
}
Subscribe to:
Posts (Atom)