diff --git a/library/think/exception/DbBindParamException.php b/library/think/exception/DbBindParamException.php new file mode 100644 index 00000000..21ddcd58 --- /dev/null +++ b/library/think/exception/DbBindParamException.php @@ -0,0 +1,26 @@ + +// +---------------------------------------------------------------------- + +namespace think\exception; + +use think\exception\DbException; + +/** + * PDO参数绑定异常 + */ +class DbBindParamException extends DbException +{ + public function __construct($message, $config, $sql, $bind, $code = 10502) + { + $this->setData('Bind Param', $bind); + parent::__construct($message, $config, $sql, $code); + } +} diff --git a/library/think/exception/DbException.php b/library/think/exception/DbException.php index a816ad6a..1a14899e 100644 --- a/library/think/exception/DbException.php +++ b/library/think/exception/DbException.php @@ -18,18 +18,19 @@ use think\Exception; */ class DbException extends Exception { - public function __construct($message, $code, $db, $config) + public function __construct($message, Array $config, $sql, $code = 10500) { $this->message = $message; $this->code = $code; - $error = explode(':', $db->getError()); $this->setData('Database Status', [ - 'Error Code' => $error[0], - 'Error Message' => $error[1], - 'Error SQL' => $db->getLastSql() + 'Error Code' => $code, + 'Error Message' => $message, + 'Error SQL' => $sql ]); $this->setData('Database Config', $config); } + + } diff --git a/library/think/exception/PDOException.php b/library/think/exception/PDOException.php new file mode 100644 index 00000000..971b1c54 --- /dev/null +++ b/library/think/exception/PDOException.php @@ -0,0 +1,34 @@ + +// +---------------------------------------------------------------------- + +namespace think\exception; + +use think\exception\DbException; + +/** + * PDO异常处理类 + * 重新封装了系统的\PDOException类 + */ +class PDOException extends DbException +{ + public function __construct(\PDOException $exception, Array $config, $sql, $code = 10501) + { + $error = $exception->errorInfo; + + $this->setData('PDO Error Info', [ + 'SQLSTATE' => $error[0], + 'Driver Error Code' => $error[1], + 'Driver Error Message' => isset($error[2]) ? $error[2] : '' + ]); + + parent::__construct($exception->getMessage(), $config, $sql, $code); + } +}