Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
/**
3
 * Error Handler with PEAR support.
4
 *
5
 * This file is part of ADOdb, a Database Abstraction Layer library for PHP.
6
 *
7
 * @package ADOdb
8
 * @link https://adodb.org Project's web site and documentation
9
 * @link https://github.com/ADOdb/ADOdb Source code and issue tracker
10
 *
11
 * The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
12
 * and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
13
 * any later version. This means you can use it in proprietary products.
14
 * See the LICENSE.md file distributed with this source code for details.
15
 * @license BSD-3-Clause
16
 * @license LGPL-2.1-or-later
17
 *
18
 * @copyright 2000-2013 John Lim
19
 * @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
20
 */
21
 
22
include_once('PEAR.php');
23
 
24
if (!defined('ADODB_ERROR_HANDLER')) define('ADODB_ERROR_HANDLER','ADODB_Error_PEAR');
25
 
26
/*
27
* Enabled the following if you want to terminate scripts when an error occurs
28
*/
29
//PEAR::setErrorHandling (PEAR_ERROR_DIE);
30
 
31
/*
32
* Name of the PEAR_Error derived class to call.
33
*/
34
if (!defined('ADODB_PEAR_ERROR_CLASS')) define('ADODB_PEAR_ERROR_CLASS','PEAR_Error');
35
 
36
/*
37
* Store the last PEAR_Error object here
38
*/
39
global $ADODB_Last_PEAR_Error; $ADODB_Last_PEAR_Error = false;
40
 
41
  /**
42
* Error Handler with PEAR support. This will be called with the following params
43
*
44
* @param $dbms		the RDBMS you are connecting to
45
* @param $fn		the name of the calling function (in uppercase)
46
* @param $errno		the native error number from the database
47
* @param $errmsg	the native error msg from the database
48
* @param $p1		$fn specific parameter - see below
49
* @param $P2		$fn specific parameter - see below
50
	*/
51
function ADODB_Error_PEAR($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false)
52
{
53
global $ADODB_Last_PEAR_Error;
54
 
55
	// Do not throw if errors are suppressed by @ operator
56
	// error_reporting() value for suppressed errors changed in PHP 8.0.0
57
	$suppressed = version_compare(PHP_VERSION, '8.0.0', '<')
58
		? 0
59
		: E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE;
60
	if (error_reporting() == $suppressed) {
61
		return;
62
	}
63
 
64
	switch($fn) {
65
	case 'EXECUTE':
66
		$sql = $p1;
67
		$inputparams = $p2;
68
 
69
		$s = "$dbms error: [$errno: $errmsg] in $fn(\"$sql\")";
70
		break;
71
 
72
	case 'PCONNECT':
73
	case 'CONNECT':
74
		$host = $p1;
75
		$database = $p2;
76
 
77
		$s = "$dbms error: [$errno: $errmsg] in $fn('$host', ?, ?, '$database')";
78
		break;
79
 
80
	default:
81
		$s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)";
82
		break;
83
	}
84
 
85
	$class = ADODB_PEAR_ERROR_CLASS;
86
	$ADODB_Last_PEAR_Error = new $class($s, $errno,
87
		$GLOBALS['_PEAR_default_error_mode'],
88
		$GLOBALS['_PEAR_default_error_options'],
89
		$errmsg);
90
 
91
	//print "<p>!$s</p>";
92
}
93
 
94
/**
95
* Returns last PEAR_Error object. This error might be for an error that
96
* occurred several sql statements ago.
97
*/
98
function ADODB_PEAR_Error()
99
{
100
global $ADODB_Last_PEAR_Error;
101
 
102
	return $ADODB_Last_PEAR_Error;
103
}