DbException.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. * @param string $message
  21. * @param array $config
  22. * @param string $sql
  23. * @param int $code
  24. */
  25. public function __construct($message, array $config, $sql, $code = 10500)
  26. {
  27. $this->message = $message;
  28. $this->code = $code;
  29. $this->setData('Database Status', [
  30. 'Error Code' => $code,
  31. 'Error Message' => $message,
  32. 'Error SQL' => $sql,
  33. ]);
  34. unset($config['username'], $config['password']);
  35. $this->setData('Database Config', $config);
  36. }
  37. }