thinkphp多表事务详解_PHP教程
时间:2021-07-01 10:21:17
帮助过:19人阅读
如下所示:
代码如下:
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();
}
}
http://www.bkjia.com/PHPjc/327670.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/327670.htmlTechArticle如下所示: 代码如下:function makeAcquire($nUsers,$nAwards) { //更新数据库 $tranDb = new Model(); $tranDb-startTrans(); for($i = 0; $i sizeof($nUsers); $i...