PHP code example of minetro / ntdb

1. Go to this page and download the library: Download minetro/ntdb library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

minetro / ntdb example snippets


$t = new Transaction(new Connection(...));
$t->begin();

$t = new Transaction(new Connection(...));
$t->begin();
// some changes..
$t->commit();

$t = new Transaction(new Connection(...));

$t->begin();
try {
	// some changes..
	$t->commit();
} catch (Exception $e) {
	$t->rollback();
}

$t = new Transaction(new Connection(...));

$t->transaction(function() {
	// some changes..
});

// or alias

$t->t(function() {
	// some changes..
});

$t = new Transaction(new Connection(...));

$t->promise()->then(
	function() {
		// Logic.. (save/update/remove some data)
	}, 
	function () {
		// Success.. (after commit)
	},
	function() {
		// Failed.. (after rollback)
	}
);

$t = new Transaction(new Connection(...));
$t->onUnresolved[] = function($exception) {
	Tracy\Debugger::log($exception);
};

use Minetro\Database\Transaction\Transaction;

class MyRepository {

	function __construct(Connection $connection) {
		$this->transaction = new Transaction($connection);
	}

	// OR

	function __construct(Context $context) {
		$this->transaction = new Transaction($context->getConnection());
	}
}

class MyPresenter {

	public function processSomething() {
		$transaction->transaction(function() {
			// Save one..

			// Make other..

			// Delete from this..

			// Update everything..
		});
	}
}