Ezpdo also supports transaction processing, which supports automatic transaction rollback and manual rollback.
First, let's take a look at the automatically rolled back transactions.
// Obtain the ezpdo Manager
$ M = epmanager: instance ();
$ OS = $ M-> Find ("from someclass as c Where C. Var = 'x '");
If (! $ OS ){
Echo "no object found \ n ";
Exit (-1 );
}
$ O = $ OS [0];
// Start the transaction with start_t ()
$ M-> start_t ();
// Changed the value
$ O-> Var = 'y ';
// End the transaction commit
$ M-> commit_t (); // by default: auto-rollback
In addition, try catch should be used to manually roll back and forth.
// Get the ezpdo Manager
$ M = epmanager: instance ();
// Find an object using ezoql
$ OS = $ M-> Find ("from someclass as c Where C. Var = 'x '");
If (! $ OS ){
Echo "no object found \ n ";
Exit (-1 );
}
$ O = $ OS [0];
// Call Manager to start transaction
$ M-> start_t ();
Try {
// Change the value of VaR in object
$ O-> Var = 'y ';
// End transaction and save changed objects
$ M-> commit_t (false); // false: No auto rollback
}
Catch (exception $ e ){
// Something wrong. rollback to old values
$ M-> rollback_t ();
// Do something here
//......
}
// 'Y' If transaction successful; 'X' if failed.
Echo $ o-> var;