1 | <?php |
||
2 | |||
3 | /** |
||
4 | * PHPPgAdmin 6.1.3 |
||
5 | */ |
||
6 | |||
7 | namespace PHPPgAdmin; |
||
8 | |||
9 | /** |
||
10 | * @file |
||
11 | * Handles Exceptions on ADODb |
||
12 | */ |
||
13 | |||
14 | /** |
||
15 | * Released under both BSD-3-CLAUSE license and GPL-2.0-OR-LATER. Whenever |
||
16 | * there is any discrepancy between the two licenses, the BSD license will take |
||
17 | * precedence. |
||
18 | * Set tabs to 4 for best viewing. |
||
19 | * Latest version is available at http://php.weblogs.com |
||
20 | * Exception-handling code using PHP5 exceptions (try-catch-throw). |
||
21 | * |
||
22 | * @author John Lim |
||
23 | * @copyright 2000-2013 John Lim <[email protected]> |
||
24 | * @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community |
||
25 | * |
||
26 | * @version Release: 5.20.9 |
||
27 | */ |
||
28 | class ADOdbException extends \Exception |
||
29 | { |
||
30 | public $dbms; |
||
31 | |||
32 | public $fn; |
||
33 | |||
34 | /** |
||
35 | * Undocumented variable. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | public $sql = ''; |
||
40 | |||
41 | /** |
||
42 | * Undocumented variable. |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | public $params = ''; |
||
47 | |||
48 | /** |
||
49 | * Undocumented variable. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | public $host = ''; |
||
54 | |||
55 | public $database = ''; |
||
56 | |||
57 | /** |
||
58 | * Undocumented variable. |
||
59 | * |
||
60 | * @var string |
||
61 | */ |
||
62 | public $msg = ''; |
||
63 | |||
64 | /** |
||
65 | * Default Error Handler. This will be called with the following params. |
||
66 | * |
||
67 | * @param string $dbms the RDBMS you are connecting to |
||
68 | * @param string $fn the name of the calling function (in uppercase) |
||
69 | * @param int $errno the native error number from the database |
||
70 | * @param string $errmsg the native error msg from the database |
||
71 | * @param string $p1 $fn specific parameter - see below |
||
72 | * @param string $p2 parameter 2 |
||
73 | * @param mixed $thisConnection connection |
||
74 | * |
||
75 | * @throws \Exception |
||
76 | */ |
||
77 | public function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection) |
||
78 | { |
||
79 | switch ($fn) { |
||
80 | case 'EXECUTE': |
||
81 | $this->sql = \is_array($p1) ? $p1[0] : $p1; |
||
82 | $this->params = $p2; |
||
83 | $s = "{$dbms} error: [{$errno}: {$errmsg}] in {$fn}(\"{$this->sql}\")"; |
||
84 | |||
85 | break; |
||
86 | case 'PCONNECT': |
||
87 | case 'CONNECT': |
||
88 | $user = $thisConnection->user; |
||
89 | $s = "{$dbms} error: [{$errno}: {$errmsg}] in {$fn}({$p1}, '{$user}', '****', {$p2})"; |
||
90 | |||
91 | break; |
||
92 | |||
93 | default: |
||
94 | $s = "{$dbms} error: [{$errno}: {$errmsg}] in {$fn}({$p1}, {$p2})"; |
||
95 | |||
96 | break; |
||
97 | } |
||
98 | |||
99 | $this->dbms = $dbms; |
||
100 | |||
101 | if ($thisConnection) { |
||
102 | $this->host = $thisConnection->host; |
||
103 | $this->database = $thisConnection->database; |
||
104 | } |
||
105 | $this->fn = $fn; |
||
106 | $this->msg = $errmsg; |
||
107 | |||
108 | if (!\is_numeric($errno)) { |
||
109 | $errno = -1; |
||
110 | } |
||
111 | |||
112 | parent::__construct($s, $errno); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Default Error Handler. This will be called with the following params. |
||
117 | * |
||
118 | * @param string $dbms the RDBMS you are connecting to |
||
119 | * @param string $fn the name of the calling function (in uppercase) |
||
120 | * @param int $errno the native error number from the database |
||
121 | * @param string $errmsg the native error msg from the database |
||
122 | * @param string $p1 $fn specific parameter - see below |
||
123 | * @param string $p2 parameter 2 |
||
124 | * @param mixed $thisConnection connection |
||
125 | * |
||
126 | * @throws \PHPPgAdmin\ADOdbException |
||
127 | * |
||
128 | * @internal param $P2 $fn specific parameter - see below |
||
129 | */ |
||
130 | public static function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection): void |
||
131 | { |
||
132 | if (0 === \error_reporting()) { |
||
133 | return; |
||
134 | } |
||
135 | |||
136 | $backtrace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
||
137 | |||
138 | $btarray0 = [ |
||
139 | 'msg' => 'ADOdbException at ', |
||
140 | 'class' => $backtrace[1]['class'], |
||
141 | 'type' => $backtrace[1]['type'], |
||
142 | 'function' => $backtrace[1]['function'], |
||
143 | 'spacer' => ' ', |
||
144 | 'line' => $backtrace[0]['line'], |
||
145 | ]; |
||
146 | $errmsg = \htmlentities(\PHPPgAdmin\ContainerUtils::br2ln($errmsg), \ENT_NOQUOTES); |
||
147 | $p1 = \htmlentities(\PHPPgAdmin\ContainerUtils::br2ln($p1), \ENT_NOQUOTES); |
||
148 | $p2 = \htmlentities(\PHPPgAdmin\ContainerUtils::br2ln($p2), \ENT_NOQUOTES); |
||
149 | |||
150 | $tag = \implode('', $btarray0); |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
151 | |||
152 | //\PC::debug(['errno' => $errno, 'fn' => $fn, 'errmsg' => $errmsg], $tag); |
||
153 | |||
154 | $adoException = new self($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection); |
||
155 | echo "<table class=\"error\" cellpadding=\"5\"><tr><td>{$adoException->msg}</td></tr></table><br />\n"; |
||
156 | |||
157 | // adodb_backtrace($adoException->getTrace()); |
||
158 | throw $adoException; |
||
159 | } |
||
160 | } |
||
161 |