Basics::Transaction
Run a callable function. The begin command will be executed before, and a commit command will be executed later. If an exception occurs, a rollback is executed. Sintaxe
namespace
ProtocolLive\PhpLiveDb;
/** */ abstract class Basics{
public function
Transaction(
}
callable
$Code,
):mixed;
bool $RunDefinedExceptionHandler = false Parameters
$Code - A callable function to be executed $RunDefinedExceptionHandler - If the custom (or default) exception handler must be executed if an exception occurs inside the callable function. Return
Returns the value returned by the callable function or the PDOException occurred See more
- Begin - Commit - Rollback - Types Examples
$consult
=
$Db->Transaction(function()
use($Db){
$id
=
$Db->Insert('users')
});->FieldAdd('email', 'a@a.com', Types::Str) ->FieldAdd('pwd', '123', Types::Str) ->Run(); $Db->Insert('socialmedias') ->FieldAdd('user_id', $id, Types::Int) ->FieldAdd('name', 'Facebook', Types::Str) ->FieldAdd('value', 'autgbavgtaga', Types::Str) ->Run(); return $id; |