Skip to content

Commit 186c4b3

Browse files
committed
- added MySQL::transaction($callback)
1 parent ac33e69 commit 186c4b3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Databases/MySQL.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,21 @@ public function transactionRollback() {
192192
$this->pdo->rollBack();
193193
return $this;
194194
}
195+
196+
/**
197+
* @param callable $callback
198+
* @throws \Exception
199+
* @return $this
200+
*/
201+
public function transaction($callback) {
202+
try {
203+
$this->pdo->beginTransaction();
204+
call_user_func($callback);
205+
$this->pdo->commit();
206+
} catch (\Exception $e) {
207+
$this->pdo->rollBack();
208+
throw $e;
209+
}
210+
return $this;
211+
}
195212
}

0 commit comments

Comments
 (0)