PDOException.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://zjzit.cn>
  10. // +----------------------------------------------------------------------
  11. namespace think\exception;
  12. /**
  13. * PDO异常处理类
  14. * 重新封装了系统的\PDOException类
  15. */
  16. class PDOException extends DbException
  17. {
  18. /**
  19. * PDOException constructor.
  20. * @param \PDOException $exception
  21. * @param array $config
  22. * @param string $sql
  23. * @param int $code
  24. */
  25. public function __construct(\PDOException $exception, array $config, $sql, $code = 10501)
  26. {
  27. $error = $exception->errorInfo;
  28. $this->setData('PDO Error Info', [
  29. 'SQLSTATE' => $error[0],
  30. 'Driver Error Code' => isset($error[1]) ? $error[1] : 0,
  31. 'Driver Error Message' => isset($error[2]) ? $error[2] : '',
  32. ]);
  33. parent::__construct($exception->getMessage(), $config, $sql, $code);
  34. }
  35. }