DbException.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. use think\Exception;
  13. /**
  14. * Database相关异常处理类
  15. */
  16. class DbException extends Exception
  17. {
  18. /**
  19. * DbException constructor.
  20. * @access public
  21. * @param string $message
  22. * @param array $config
  23. * @param string $sql
  24. * @param int $code
  25. */
  26. public function __construct($message, array $config = [], $sql = '', $code = 10500)
  27. {
  28. $this->message = $message;
  29. $this->code = $code;
  30. $this->setData('Database Status', [
  31. 'Error Code' => $code,
  32. 'Error Message' => $message,
  33. 'Error SQL' => $sql,
  34. ]);
  35. unset($config['username'], $config['password']);
  36. $this->setData('Database Config', $config);
  37. }
  38. }