1 | <?php |
||
2 | /** |
||
3 | * @link https://www.yiiframework.com/ |
||
4 | * @copyright Copyright (c) 2008 Yii Software LLC |
||
5 | * @license https://www.yiiframework.com/license/ |
||
6 | */ |
||
7 | |||
8 | namespace yii\db; |
||
9 | |||
10 | /** |
||
11 | * Exception represents an exception that is caused by some DB-related operations. |
||
12 | * |
||
13 | * @author Qiang Xue <[email protected]> |
||
14 | * @since 2.0 |
||
15 | */ |
||
16 | class Exception extends \yii\base\Exception |
||
17 | { |
||
18 | /** |
||
19 | * @var array the error info provided by a PDO exception. This is the same as returned |
||
20 | * by [PDO::errorInfo](https://www.php.net/manual/en/pdo.errorinfo.php). |
||
21 | */ |
||
22 | public $errorInfo = []; |
||
23 | |||
24 | |||
25 | /** |
||
26 | * Constructor. |
||
27 | * @param string $message PDO error message |
||
28 | * @param array $errorInfo PDO error info |
||
29 | * @param string $code PDO error code |
||
30 | * @param \Throwable|null $previous The previous exception used for the exception chaining. |
||
31 | */ |
||
32 | 2 | public function __construct($message, $errorInfo = [], $code = '', $previous = null) |
|
33 | { |
||
34 | 2 | parent::__construct($message, 0, $previous); |
|
35 | 2 | $this->errorInfo = $errorInfo; |
|
36 | 2 | $this->code = $code; |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * @return string the user-friendly name of this exception |
||
41 | */ |
||
42 | public function getName() |
||
43 | { |
||
44 | return 'Database Exception'; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @return string readable representation of exception |
||
49 | */ |
||
50 | public function __toString() |
||
51 | { |
||
52 | return parent::__toString() . PHP_EOL |
||
53 | . 'Additional Information:' . PHP_EOL . print_r($this->errorInfo, true); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
54 | } |
||
55 | } |
||
56 |