Php orm framework ezpdo (3) Transaction

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.