Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

   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  	function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
  34  	 {
  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;
  41  
  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  	 	 	 //Prevent PHP warning if $p1 or $p2 are arrays.
  49  	 	 	 $p1 = ( is_array($p1) ) ? 'Array' : $p1;
  50  	 	 	 $p2 = ( is_array($p2) ) ? 'Array' : $p2;
  51  	 	 	 $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)";
  52  	 	 	 break;
  53  	 	 }
  54  
  55  	 	 $this->dbms = $dbms;
  56  	 	 if ($thisConnection) {
  57  	 	 	 $this->host = $thisConnection->host;
  58  	 	 	 $this->database = $thisConnection->database;
  59  	 	 }
  60  	 	 $this->fn = $fn;
  61  	 	 $this->msg = $errmsg;
  62  
  63  	 	 if (!is_numeric($errno)) $errno = -1;
  64  	 	 parent::__construct($s,$errno);
  65  	 }
  66  }
  67  
  68  /**
  69  * Default Error Handler.
  70  *
  71  * @param string $dbms    the RDBMS you are connecting to
  72  * @param string $fn      the name of the calling function (in uppercase)
  73  * @param int    $errno   the native error number from the database
  74  * @param string $errmsg  the native error msg from the database
  75  * @param mixed  $p1      $fn specific parameter - see below
  76  * @param mixed  $p2      $fn specific parameter - see below
  77  */
  78  
  79  function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
  80  {
  81  global $ADODB_EXCEPTION;
  82  
  83  	 if (error_reporting() == 0) return; // obey @ protocol
  84  	 if (is_string($ADODB_EXCEPTION)) $errfn = $ADODB_EXCEPTION;
  85  	 else $errfn = 'ADODB_EXCEPTION';
  86  	 throw new $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection);
  87  }