weekly release 4.5dev
[moodle.git] / lib / adodb / adodb-errorpear.inc.php
blob7b173da84fd8133d7e31ffe76715406082fc7056
1 <?php
2 /**
3 * Error Handler with PEAR support.
5 * This file is part of ADOdb, a Database Abstraction Layer library for PHP.
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
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
18 * @copyright 2000-2013 John Lim
19 * @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
22 include_once('PEAR.php');
24 if (!defined('ADODB_ERROR_HANDLER')) define('ADODB_ERROR_HANDLER','ADODB_Error_PEAR');
27 * Enabled the following if you want to terminate scripts when an error occurs
29 //PEAR::setErrorHandling (PEAR_ERROR_DIE);
32 * Name of the PEAR_Error derived class to call.
34 if (!defined('ADODB_PEAR_ERROR_CLASS')) define('ADODB_PEAR_ERROR_CLASS','PEAR_Error');
37 * Store the last PEAR_Error object here
39 global $ADODB_Last_PEAR_Error; $ADODB_Last_PEAR_Error = false;
41 /**
42 * Error Handler with PEAR support. This will be called with the following params
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
51 function ADODB_Error_PEAR($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false)
53 global $ADODB_Last_PEAR_Error;
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;
64 switch($fn) {
65 case 'EXECUTE':
66 $sql = $p1;
67 $inputparams = $p2;
69 $s = "$dbms error: [$errno: $errmsg] in $fn(\"$sql\")";
70 break;
72 case 'PCONNECT':
73 case 'CONNECT':
74 $host = $p1;
75 $database = $p2;
77 $s = "$dbms error: [$errno: $errmsg] in $fn('$host', ?, ?, '$database')";
78 break;
80 default:
81 $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)";
82 break;
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);
91 //print "<p>!$s</p>";
94 /**
95 * Returns last PEAR_Error object. This error might be for an error that
96 * occurred several sql statements ago.
98 function ADODB_PEAR_Error()
100 global $ADODB_Last_PEAR_Error;
102 return $ADODB_Last_PEAR_Error;