$tt = Yii::$app->db->beginTransaction();//开启事务 try { //执行一系列数据库操作 $tt->commit(); //没有报错就提交 } catch (Exception $e){ $tt->rollBack(); //报错回滚 }