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