No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PDOException.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. * @access public
  21. * @param \PDOException $exception
  22. * @param array $config
  23. * @param string $sql
  24. * @param int $code
  25. */
  26. public function __construct(\PDOException $exception, array $config, $sql, $code = 10501)
  27. {
  28. $error = $exception->errorInfo;
  29. $this->setData('PDO Error Info', [
  30. 'SQLSTATE' => $error[0],
  31. 'Driver Error Code' => isset($error[1]) ? $error[1] : 0,
  32. 'Driver Error Message' => isset($error[2]) ? $error[2] : '',
  33. ]);
  34. parent::__construct($exception->getMessage(), $config, $sql, $code);
  35. }
  36. }