Nested transactions for Dibi.
Download a latest package or use Composer:
composer require inlm/dibi-transactions
Inlm\Dibi-transactions requires PHP 5.6.0 or later and Dibi.
$connection = new Dibi\Connection();
$transactions = new Inlm\DibiTransactions\Transactions($connection);
$value = $transactions->transactional(function () use ($connection) {
$connection->query('...');
$connection->query('...');
return $value;
});
$transaction = $transactions->createTransaction();
try {
$connection->query('...');
$connection->query('...');
$transaction->commit();
} catch (Exception $e) {
$transaction->rollback();
throw $e;
}
Object Transaction
throws error if you forget to call commit()
or rollback()
. It can be connected with Tracy:
$transactions->onUnresolved[] = array(Inlm\DibiTransactions\Bridges\Tracy::class, 'logUnresolved');
try {
$transactions->begin();
$connection->query('...');
$connection->query('...');
$transactions->commit();
} catch (Exception $e) {
$transactions->rollback();
}
License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/