标签:数据库 function round commit tar 文件 判断 cut llb
数据库中数据表类型Innodb
controller 层文件
$m = M();
$m->startTrans();
$shop = $m->query(‘SELECT * FROM `think_shop` WHERE id=‘.$custom[‘shop_id‘].‘ FOR UPDATE‘);
$shop = $shop[‘0‘];
$ret1 = D(‘Transaction‘)->goodsNum(参数1,参数2, $m);
if(!$ret1) {
$m->rollback();
} else {
$m->commit();
}
model 层文件
public function goodsNum(参数1,参数2, $m) {
操作....
//$ret1 = $m->execute("UPDATE `think_shop_goods` SET `stock` = stock-".$goodsNum[$key]." WHERE goods_id=".$goodsId." AND shop_id = ".$shop[‘id‘]);
//判断结果 返回true 或者 false
if(! $ret1) {
return false;
} else {
return true;
}
}
注意model层不需commit和rollback
标签:数据库 function round commit tar 文件 判断 cut llb
原文地址:https://www.cnblogs.com/qizishuo/p/8880905.html