Helper.php 878 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. *
  13. * @return void
  14. * @throws \LogicException
  15. */
  16. static public function check_tr()
  17. {
  18. $level = DB::transactionLevel();
  19. if ($level === 0) {
  20. $w =( debug_backtrace()[1]['file'] ??' file '). ':' . (debug_backtrace()[1]['line']??'line');
  21. Logger::error("check_tr - transaction level is 0 没有开启事务" . $w);
  22. // 没有开启事务
  23. throw new \LogicException("transaction level is 0");
  24. }
  25. if ($level > 1) {
  26. // 事务嵌套
  27. Logger::error("check_tr - transaction level >1 事务嵌套 ");
  28. throw new \LogicException("transaction level > 1");
  29. }
  30. }
  31. }