]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/adodb/adodb-errorpear.inc.php
Reformat code
[SourceForge/phpwiki.git] / lib / WikiDB / adodb / adodb-errorpear.inc.php
1 <?php
2 /**
3  * @version V4.22 15 Apr 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
4  * Released under both BSD license and Lesser GPL library license.
5 Whenever there is any discrepancy between the two licenses,
6 the BSD license will take precedence.
7  *
8  * Set tabs to 4 for best viewing.
9  *
10  * Latest version is available at http://php.weblogs.com
11  *
12  */
13 include_once 'PEAR.php';
14
15 define('ADODB_ERROR_HANDLER', 'ADODB_Error_PEAR');
16
17 /*
18 * Enabled the following if you want to terminate scripts when an error occurs
19 */
20 //PEAR::setErrorHandling (PEAR_ERROR_DIE);
21
22 /*
23 * Name of the PEAR_Error derived class to call.
24 */
25 if (!defined('ADODB_PEAR_ERROR_CLASS')) define('ADODB_PEAR_ERROR_CLASS', 'PEAR_Error');
26
27 /*
28 * Store the last PEAR_Error object here
29 */
30 global $ADODB_Last_PEAR_Error;
31 $ADODB_Last_PEAR_Error = false;
32
33 /**
34  * Error Handler with PEAR support. This will be called with the following params
35  *
36  * @param $dbms        the RDBMS you are connecting to
37  * @param $fn        the name of the calling function (in uppercase)
38  * @param $errno        the native error number from the database
39  * @param $errmsg    the native error msg from the database
40  * @param $p1        $fn specific parameter - see below
41  * @param $P2        $fn specific parameter - see below
42  */
43 function ADODB_Error_PEAR($dbms, $fn, $errno, $errmsg, $p1 = false, $p2 = false)
44 {
45     global $ADODB_Last_PEAR_Error;
46
47     if (error_reporting() == 0) return; // obey @ protocol
48     switch ($fn) {
49         case 'EXECUTE':
50             $sql = $p1;
51             $inputparams = $p2;
52
53             $s = "$dbms error: [$errno: $errmsg] in $fn(\"$sql\")";
54             break;
55
56         case 'PCONNECT':
57         case 'CONNECT':
58             $host = $p1;
59             $database = $p2;
60
61             $s = "$dbms error: [$errno: $errmsg] in $fn('$host', ?, ?, '$database')";
62             break;
63
64         default:
65             $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)";
66             break;
67     }
68
69     $class = ADODB_PEAR_ERROR_CLASS;
70     $ADODB_Last_PEAR_Error = new $class($s, $errno,
71         $GLOBALS['_PEAR_default_error_mode'],
72         $GLOBALS['_PEAR_default_error_options'],
73         $errmsg);
74
75     //print "<p>!$s</p>";
76 }
77
78 /**
79  * Returns last PEAR_Error object. This error might be for an error that
80  * occured several sql statements ago.
81  */
82 function &ADODB_PEAR_Error()
83 {
84     global $ADODB_Last_PEAR_Error;
85
86     return $ADODB_Last_PEAR_Error;
87 }