#################################### 测试事务
// 启动事务
Db::startTrans();
try {
//插入行为表
$data = [
'userId' => 'test111',
'createtime'=> '2019-06-28 17:23:02',
'score' => 2,
'action' => '',
'scoreLater'=>55,
];
Db::table('fa_ngzb_scoreflow')->insert($data);//插入成功
//插入行为表
$data = [
'userId' => 'test222',
'sourceId' => 456,
'api_num' => 'a', // 数据表类型错误
'createtime'=>'2019-06-28 17:23:02',
'start_time'=> '2019-06-28 17:23:02',
'end_time' => '2019-06-28 17:23:02',
'score' => 2,
];
Db::table('fa_ngzb_reader')->insert($data); //插入失败
// 提交事务
Db::commit();
} catch (\Exception $e) {
// 回滚事务
// dump($e->getMessage()); //打印错误
Db::rollback(); //同时回滚,将不会插入任何一条 } ####################################