Conditions | 6 |
Paths | 15 |
Total Lines | 22 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | public function __construct($message, \Exception $previous = null) |
||
11 | { |
||
12 | $code = self::CODE; |
||
13 | if ($previous instanceof \PDOException) { |
||
14 | if (!empty($previous->errorInfo[1])) { |
||
15 | $code = $previous->errorInfo[1]; |
||
16 | $this->sqlState = $previous->errorInfo[0]; |
||
17 | } |
||
18 | if (!empty($previous->errorInfo[2])) { |
||
19 | // cleaner error message without all the codes. |
||
20 | $message = $previous->errorInfo[2]; |
||
21 | } |
||
22 | } |
||
23 | if ($previous instanceof \mysqli_sql_exception) { |
||
24 | // https://stackoverflow.com/a/21081034 |
||
25 | $array = (array) $previous; |
||
26 | if (!empty($array['\0*\0sqlstate'])) { |
||
27 | $this->sqlState = $array['\0*\0sqlstate']; |
||
28 | } |
||
29 | } |
||
30 | |||
31 | parent::__construct($message, $code, $previous); |
||
32 | } |
||
39 |