thinkphp 多表 事务详解_php技巧
程序员文章站
2022-03-27 13:13:46
...
如下所示:
function makeAcquire($nUsers,$nAwards)
{
//更新数据库
$tranDb = new Model();
$tranDb->startTrans();
for($i = 0; $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();
}
}
复制代码 代码如下:
function makeAcquire($nUsers,$nAwards)
{
//更新数据库
$tranDb = new Model();
$tranDb->startTrans();
for($i = 0; $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();
}
}
推荐阅读