Skip to content

hatyuki/php-TransactionManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

TransactionManager - transaction handling for database.

SYNOPSIS

basic usage:

require_once 'TransactionManager.php';
$pdo = new PDO('sqlite::memory:');
$tm  = TransactionManager($pdo);

$tm->txn_begin( );
    $pdo->query("INSERT INTO foo (id, var) VALUES (1, 'baz')";
$tm->txn_commit( );

scope_gurad usage:

require_once 'TransactionManager.php';
$pdo = new PDO('sqlite::memory:');
$tm  = TransactionManager($pdo);

my $txn = $tm->txn_scope( );
    $pdo->query("INSERT INTO foo (id, var) VALUES (1, 'baz')";
$txn->commit( );

nested transaction usage:

require_once 'TransactionManager.php';
$pdo = new PDO('sqlite::memory:');
$tm  = TransactionManager($pdo);

$txn1 = $tm->txn_scope( );
    $pdo->query("INSERT INTO foo (id, var) VALUES (1, 'baz')";
    
    $txn2 = $tm->txn_scope( );
        $pdo->query("INSERT INTO foo (id, var) VALUES (2, 'bab')";
    $txn2->commit( );

    $txn3 = $tm->txn_scope( );
        $pdo->query("INSERT INTO foo (id, var) VALUES (3, 'bee')";
    $txn3->commit( );
$txn1->commit( );

DESCRIPTION

TransactionManager is a simple transaction manager. based on DBIx::TransactionManager

TransactionManager's METHODS

$tm = TransactionManager->new($dbh)

get TransactionManager's instance object. $pdo parameter must be required.

$txn = $tm->txn_scope( )

get TransactionManagerScopeGuard's instance object.

$tm->txn_begin( )

Start the transaction.

$tm->txn_rollback( )

Rollback the transaction.

$tm->txn_commit( )

Commit the transaction.

$tm->in_transaction( )

are you in transaction?

TransactionManagerScopeGuard's METHODS

$txn->commit( )

Commit the transaction.

$txn->rollback( )

Rollback the transaction.

SEE ALSO

About

Transaction management class of PDO (PHP)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages