更新DB异常显示

This commit is contained in:
麦当苗儿
2016-02-01 00:03:15 +08:00
parent 0c825c6954
commit 5cbce8ea74
3 changed files with 66 additions and 5 deletions

View 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);
}
}

View File

@@ -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);
}
}

View 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);
}
}