public static function transaction($connection, callable $function, $context = null)
	{
		static::_connection($connection);
		static::_associate($function, $context);

		return function() use ($connection, $function) {
			if (!$connection->beginTransaction())
				throw new \RuntimeException("unable to begin transaction");

			try {
				if (call_user_func_array($function, func_get_args()) === false)
					goto rollback;
			} catch (\PDOException $e) {
				throw $e;
			} catch (\Exception $e) {
				goto rollback;
			}

			if (!$connection->commit())
				throw new \RuntimeException("unable to commit transaction");

			return true;

			rollback:
			if (!$connection->rollback())
				throw new \RuntimeException("unable to rollback transaction");

			return false;
		};
	}
public static function transaction($connection, callable $function, $context = null)
	{
		static::_connection($connection);
		static::_associate($function, $context);

		return function() use ($connection, $function) {
			if (!$connection->beginTransaction())
				throw new \RuntimeException("unable to begin transaction");

			try {
				if (call_user_func_array($function, func_get_args()) === false)
					goto rollback;
			} catch (\PDOException $e) {
				throw $e;
			} catch (\Exception $e) {
				goto rollback;
			}

			if (!$connection->commit())
				throw new \RuntimeException("unable to commit transaction");

			return true;

			rollback:
			if (!$connection->rollback())
				throw new \RuntimeException("unable to rollback transaction");

			return false;
		};
	}
public static function transaction ( $ connection , callable $ function , $ context = null ) { static :: _connection ( $ connection ) ; static :: _associate ( $ function , $ context ) ; return function ( ) use ( $ connection , $ function ) { if ( ! $ connection -> beginTransaction ( ) ) throw new \ RuntimeException ( "unable to begin transaction" ) ; try { if ( call_user_func_array ( $ function , func_get_args ( ) ) === false ) goto rollback ; } catch ( \ PDOException $ e ) { throw $ e ; } catch ( \ Exception $ e ) { goto rollback ; } if ( ! $ connection -> commit ( ) ) throw new \ RuntimeException ( "unable to commit transaction" ) ; return true ; rollback : if ( ! $ connection -> rollback ( ) ) throw new \ RuntimeException ( "unable to rollback transaction" ) ; return false ; } ; }
Wraps the function inside a transaction-safe function. The transaction will be rolled-back if the wrapped
function returns FALSE or throws any exception, otherwise it will be committed. The wrapper function returns
true if the transaction was sucessfully comited, false otherwise. If the transaction cannot be started, commited
or rollbacked, an exception is thrown. If a PDOException is thrown during wrapped function execution, it will be
rethrown for debugging purposes.

@category Database Functions

@param string,PDO $connection the database connection name or PDO instance
@param callable $function the wrapped function
@param object $context optional, if provided will become the context of $function

@throws RuntimeException transaction cannot be started, commited, or rollbacked

@return closure
Wraps the function inside a transaction - safe function . The transaction will be rolled - back if the wrapped function returns FALSE or throws any exception otherwise it will be committed . The wrapper function returns true if the transaction was sucessfully comited false otherwise . If the transaction cannot be started commited or rollbacked an exception is thrown . If a PDOException is thrown during wrapped function execution it will be rethrown for debugging purposes .