1<?php
2
3/**
4 * @version V4.66 28 Sept 2005  (c) 2000-2005 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
17if (!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR);
18define('ADODB_ERROR_HANDLER','adodb_throw');
19
20class ADODB_Exception extends Exception {
21var $dbms;
22var $fn;
23var $sql = '';
24var $params = '';
25var $host = '';
26var $database = '';
27
28	function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
29	{
30		switch($fn) {
31		case 'EXECUTE':
32			$this->sql = $p1;
33			$this->params = $p2;
34			$s = "$dbms error: [$errno: $errmsg] in $fn(\"$p1\")\n";
35			break;
36
37		case 'PCONNECT':
38		case 'CONNECT':
39			$user = $thisConnection->user;
40			$s = "$dbms error: [$errno: $errmsg] in $fn($p1, '$user', '****', $p2)\n";
41			break;
42		default:
43			$s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)\n";
44			break;
45		}
46
47		$this->dbms = $dbms;
48		$this->host = $thisConnection->host;
49		$this->database = $thisConnection->database;
50		$this->fn = $fn;
51		$this->msg = $errmsg;
52
53		if (!is_numeric($errno)) $errno = -1;
54		parent::__construct($s,$errno);
55	}
56}
57
58/**
59* Default Error Handler. This will be called with the following params
60*
61* @param $dbms		the RDBMS you are connecting to
62* @param $fn		the name of the calling function (in uppercase)
63* @param $errno		the native error number from the database
64* @param $errmsg	the native error msg from the database
65* @param $p1		$fn specific parameter - see below
66* @param $P2		$fn specific parameter - see below
67*/
68
69function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
70{
71global $ADODB_EXCEPTION;
72
73	if (error_reporting() == 0) return; // obey @ protocol
74	if (is_string($ADODB_EXCEPTION)) $errfn = $ADODB_EXCEPTION;
75	else $errfn = 'ADODB_EXCEPTION';
76	throw new $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection);
77}
78
79
80?>