Automatically generated installer lang files
[moodle.git] / lib / adodb / adodb-exceptions.inc.php
blob9f1176f0f6936470aa953979fc7754a2c4e362b5
1 <?php
2 /**
3 * Error handling using Exceptions.
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 if (!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR);
23 define('ADODB_ERROR_HANDLER','adodb_throw');
25 class ADODB_Exception extends Exception {
26 var $dbms;
27 var $fn;
28 var $sql = '';
29 var $params = '';
30 var $host = '';
31 var $database = '';
33 function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
35 switch($fn) {
36 case 'EXECUTE':
37 $this->sql = is_array($p1) ? $p1[0] : $p1;
38 $this->params = $p2;
39 $s = "$dbms error: [$errno: $errmsg] in $fn(\"$this->sql\")";
40 break;
42 case 'PCONNECT':
43 case 'CONNECT':
44 $user = $thisConnection->user;
45 $s = "$dbms error: [$errno: $errmsg] in $fn($p1, '$user', '****', $p2)";
46 break;
47 default:
48 $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)";
49 break;
52 $this->dbms = $dbms;
53 if ($thisConnection) {
54 $this->host = $thisConnection->host;
55 $this->database = $thisConnection->database;
57 $this->fn = $fn;
58 $this->msg = $errmsg;
60 if (!is_numeric($errno)) $errno = -1;
61 parent::__construct($s,$errno);
65 /**
66 * Default Error Handler.
68 * @param string $dbms the RDBMS you are connecting to
69 * @param string $fn the name of the calling function (in uppercase)
70 * @param int $errno the native error number from the database
71 * @param string $errmsg the native error msg from the database
72 * @param mixed $p1 $fn specific parameter - see below
73 * @param mixed $p2 $fn specific parameter - see below
76 function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
78 global $ADODB_EXCEPTION;
80 if (error_reporting() == 0) return; // obey @ protocol
81 if (is_string($ADODB_EXCEPTION)) $errfn = $ADODB_EXCEPTION;
82 else $errfn = 'ADODB_EXCEPTION';
83 throw new $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection);