Helper.php 756 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace UCore\Db;
  3. use Illuminate\Support\Facades\DB;
  4. use UCore\Helper\Logger;
  5. /**
  6. * 数据库助手类
  7. */
  8. class Helper
  9. {
  10. /**
  11. * 检查是否已经开启事务
  12. * @throws \LogicException
  13. * @return void
  14. */
  15. static public function check_tr()
  16. {
  17. $level = DB::transactionLevel();
  18. if($level === 0){
  19. Logger::error("check_tr - transaction level is 0 没有开启事务");
  20. // 没有开启事务
  21. throw new \LogicException("transaction level is 0");
  22. }
  23. if($level > 1){
  24. // 事务嵌套
  25. Logger::error("check_tr - transaction level >1 事务嵌套 ");
  26. throw new \LogicException("transaction level > 1");
  27. }
  28. }
  29. }