mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
更新DB异常显示
This commit is contained in:
26
library/think/exception/DbBindParamException.php
Normal file
26
library/think/exception/DbBindParamException.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
34
library/think/exception/PDOException.php
Normal file
34
library/think/exception/PDOException.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user