Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]
1 <?php 2 /** 3 * Error handling using Exceptions. 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 if (!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR); 23 define('ADODB_ERROR_HANDLER','adodb_throw'); 24 25 class ADODB_Exception extends Exception { 26 var $dbms; 27 var $fn; 28 var $sql = ''; 29 var $params = ''; 30 var $host = ''; 31 var $database = ''; 32 33 /** @var string A message text. */ 34 var $msg = ''; 35 36 function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection) 37 { 38 switch($fn) { 39 case 'EXECUTE': 40 $this->sql = is_array($p1) ? $p1[0] : $p1; 41 $this->params = $p2; 42 $s = "$dbms error: [$errno: $errmsg] in $fn(\"$this->sql\")"; 43 break; 44 45 case 'PCONNECT': 46 case 'CONNECT': 47 $user = $thisConnection->user; 48 $s = "$dbms error: [$errno: $errmsg] in $fn($p1, '$user', '****', $p2)"; 49 break; 50 default: 51 //Prevent PHP warning if $p1 or $p2 are arrays. 52 $p1 = ( is_array($p1) ) ? 'Array' : $p1; 53 $p2 = ( is_array($p2) ) ? 'Array' : $p2; 54 $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)"; 55 break; 56 } 57 58 $this->dbms = $dbms; 59 if ($thisConnection) { 60 $this->host = $thisConnection->host; 61 $this->database = $thisConnection->database; 62 } 63 $this->fn = $fn; 64 $this->msg = $errmsg; 65 66 if (!is_numeric($errno)) $errno = -1; 67 parent::__construct($s,$errno); 68 } 69 } 70 71 /** 72 * Default Error Handler. 73 * 74 * @param string $dbms the RDBMS you are connecting to 75 * @param string $fn the name of the calling function (in uppercase) 76 * @param int $errno the native error number from the database 77 * @param string $errmsg the native error msg from the database 78 * @param mixed $p1 $fn specific parameter - see below 79 * @param mixed $p2 $fn specific parameter - see below 80 */ 81 82 function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection) 83 { 84 global $ADODB_EXCEPTION; 85 86 if (error_reporting() == 0) return; // obey @ protocol 87 if (is_string($ADODB_EXCEPTION)) $errfn = $ADODB_EXCEPTION; 88 else $errfn = 'ADODB_EXCEPTION'; 89 throw new $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection); 90 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body