pdo:transactions
PDO - Transactions
Here's an example of using transactions in PDO.
NOTE: Calling beginTransaction() turns off auto commit automatically.
<?php try { $db->beginTransaction(); $db->exec("SOME QUERY"); $stmt = $db->prepare("SOME OTHER QUERY?"); $stmt->execute(array($value)); $stmt = $db->prepare("YET ANOTHER QUERY??"); $stmt->execute(array($value2, $value3)); $db->commit(); } catch(PDOException $ex) { // Something went wrong rollback! $db->rollBack(); echo $ex->getMessage(); }
pdo/transactions.txt · Last modified: 2020/07/15 09:30 by 127.0.0.1