inlm/dibi-transactions

Nested transactions for Dibi.

v0.7.1 2018-09-05 16:46 UTC

This package is auto-updated.

Last update: 2020-07-13 22:35:39 UTC


README

Nested transactions for Dibi.

Become a Patron! Buy me a coffee

Installation

Download a latest package or use Composer:

composer require inlm/dibi-transactions

Inlm\Dibi-transactions requires PHP 5.4.0 or later and Dibi.

Usage

$connection = new Dibi\Connection();
$transactions = new Inlm\DibiTransactions\Transactions($connection);

transactional()

$transactions->transactional(function () use ($connection) {
	$connection->query('...');
	$connection->query('...');
});

Transaction

$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', 'logUnresolved');

begin / commit / rollback

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/