How to implement multiple tables and transactions in thinkphp
This article mainly introduces how to achieve multiple tables and transactions in thinkphp. It is very detailed and has a certain reference value. Friends who are interested must read it!
As follows:
Function makeAcquire ($nUsers,$nAwards)
{
/ / Update the database
$tranDb = new Model ()
$tranDb- > startTrans ()
For ($I = 0; $I
< sizeof($nUsers); $i++) { //更新表Acquire $flagAc = $tranDb->Table ('Acquire')-> add ($acquire)
/ / Update table Users
$where = array ('utiliti' = > $nUsers [$I] ['upliid'])
$flagU = $tranDb- > table ('Users')-> where ($where)-> setInc
$where = array ('aroomidservant = > $nAwards [$I] [' aroomid'])
$flagA = $tranDb- > table ('Award')-> where ($where)-> setDec
}
If ($flagAc & & $flagU & & $flagA)
{
$tranDb- > commit ()
}
Else
{
$tranDb- > rollback ()
}
}
These are all the contents of the article "how to implement multiple tables and transactions in thinkphp". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!