Reputation: 3875
I would like to use transaction in some critical areas of my code, but really not for everything I do. I just learnt that there is an AUTOCOMMIT value that is set to 1 by default, and I should set it to 0 if I want to START TRANSACTION and COMMIT or ROLLBACK.
Upvotes: 1
Views: 162
Reputation: 164731
Using PDO
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->beginTransaction();
try {
// do stuff
$pdo->commit();
} catch (Exception $ex) {
$pdo->rollBack();
throw $ex;
}
Upvotes: 2