]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/adodb/adodb-exceptions.inc.php
new ADODB library 4.22 with multiple drivers (not only mysql as before), major change...
[SourceForge/phpwiki.git] / lib / WikiDB / adodb / adodb-exceptions.inc.php
1 <?php\r
2 \r
3 /**\r
4  * @version V4.22 15 Apr 2004  (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.\r
5  * Released under both BSD license and Lesser GPL library license.\r
6  * Whenever there is any discrepancy between the two licenses,\r
7  * the BSD license will take precedence.\r
8  *\r
9  * Set tabs to 4 for best viewing.\r
10  *\r
11  * Latest version is available at http://php.weblogs.com\r
12  *\r
13  * Exception-handling code using PHP5 exceptions (try-catch-throw).\r
14  */\r
15         \r
16 if (!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR); \r
17 define('ADODB_ERROR_HANDLER','adodb_throw');\r
18 \r
19 class ADODB_Exception extends Exception {\r
20 var $dbms;\r
21 var $fn;\r
22 var $sql = '';\r
23 var $params = '';\r
24 var $host = '';\r
25 var $database = '';\r
26         \r
27         function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)\r
28         {\r
29                 switch($fn) {\r
30                 case 'EXECUTE':\r
31                         $this->sql = $p1;\r
32                         $this->params = $p2;\r
33                         $s = "$dbms error: [$errno: $errmsg] in $fn(\"$p1\")\n";\r
34                         break;\r
35         \r
36                 case 'PCONNECT':\r
37                 case 'CONNECT':\r
38                         $user = $thisConnection->user;\r
39                         $s = "$dbms error: [$errno: $errmsg] in $fn($p1, '$user', '****', $p2)\n";\r
40                         break;\r
41                 default:\r
42                         $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)\n";\r
43                         break;\r
44                 }\r
45         \r
46                 $this->dbms = $dbms;\r
47                 $this->host = $thisConnection->host;\r
48                 $this->database = $thisConnection->database;\r
49                 $this->fn = $fn;\r
50                 $this->msg = $errmsg;\r
51                                 \r
52                 if (!is_numeric($errno)) $errno = -1;\r
53                 parent::__construct($s,$errno);\r
54         }\r
55 }\r
56 \r
57 /**\r
58 * Default Error Handler. This will be called with the following params\r
59 *\r
60 * @param $dbms          the RDBMS you are connecting to\r
61 * @param $fn            the name of the calling function (in uppercase)\r
62 * @param $errno         the native error number from the database\r
63 * @param $errmsg        the native error msg from the database\r
64 * @param $p1            $fn specific parameter - see below\r
65 * @param $P2            $fn specific parameter - see below\r
66 */\r
67 \r
68 function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)\r
69 {\r
70 global $ADODB_EXCEPTION;\r
71 \r
72         if (is_string($ADODB_EXCEPTION)) $errfn = $ADODB_EXCEPTION;\r
73         else $errfn = 'ADODB_EXCEPTION';\r
74         throw new $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection);\r
75 }\r
76 \r
77 \r
78 ?>