thinkphp多表事务详解_php技巧
时间:2021-07-01 10:21:17
帮助过:4人阅读
如下所示:
代码如下:
function makeAcquire($nUsers,$nAwards)
{
//更新数据库
$tranDb = new Model();
$tranDb->startTrans();
for($i = 0; $i < sizeof($nUsers); $i++)
{
//更新表Acquire
$flagAc = $tranDb->table('Acquire')->add($acquire);
//更新表Users
$where = array('u_id'=>$nUsers[$i]['u_id']);
$flagU = $tranDb->table('Users')->where($where)->setInc('u_man_count',1);
//更新表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();
}
}