Thinkphp multi-table transaction detail_php tutorial

Source: Internet
Author: User
Thinkphp multi-table transaction details. Copy the code as follows: functionmakeAcquire ($ nUsers, $ nAwards) {update database $ tranDbnewModel (); $ tranDb-startTrans (); for ($ i0; $ isizeof ($ nUsers); $ I is as follows:

The code is as follows:


Function makeAcquire ($ nUsers, $ nAwards)
{
// Update the database
$ TranDb = new Model ();
$ TranDb-> startTrans ();
For ($ I = 0; $ I <sizeof ($ nUsers); $ I ++)
{
// Update The Acquire table
$ FlagAc = $ tranDb-> table ('acquire ')-> add ($ Acquire );
// Update the Users table
$ Where = array ('U _ id' => $ nUsers [$ I] ['U _ id']);
$ FlagU = $ tranDb-> table ('users')-> where ($ where)-> setInc ('U _ man_count ', 1 );
// Update the table Award
$ Where = array ('a _ id' => $ nAwards [$ I] ['A _ id']);
$ FlagA = $ tranDb-> table ('award ')-> where ($ where)-> setDec ('a _ count', 1 );
}
If ($ flagAc & $ flagU & $ flagA)
{
$ TranDb-> commit ();
}
Else
{
$ TranDb-> rollback ();
}
}


The pipeline code is as follows: function makeAcquire ($ nUsers, $ nAwards) {// update database $ tranDb = new Model (); $ tranDb-startTrans (); for ($ I = 0; $ I sizeof ($ nUsers); $ I...

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.