实例如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
//开启mysql事务操作
$model = M();
$model ->startTrans();
$flag =false;
$deal1 = M( 'ppdd' )->where( array ( 'id' => $data_P [ 'id' ], 'zt' => '0' ))->save( $data_arr );
$deal2 = M( 'tgbz' )->where( array ( 'id' => $ppddxx [ 'p_id' ]))->save( array ( 'is_dakuan' =>1, 'bj' => '2' , 'date_hk' => date ( 'Y-m-d H:i:s' , time ())));
$deal3 = M( 'jsbz' )->where( array ( 'id' => $ppddxx [ 'g_id' ]))->save( array ( 'bj' => '2' ));
if ( $deal1 && $deal2 * $deal3 ){
$flag =true;
}
if ( $flag ){
$model ->commit();
}
else {
$model ->rollback();
die ( "<script>alert('提交失败,请重新提交!');history.back(-1);</script>" );
}
|
以上这篇Thinkphp事务操作实例(推荐)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。