Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

   1  <?php
   2  
   3  /**
   4   * @version   v5.20.16  12-Jan-2020
   5   * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
   6   * @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
   7   * Released under both BSD license and Lesser GPL library license.
   8   * Whenever there is any discrepancy between the two licenses,
   9   * the BSD license will take precedence.
  10   *
  11   * Set tabs to 4 for best viewing.
  12   *
  13   * Latest version is available at http://adodb.org/
  14   *
  15   * Exception-handling code using PHP5 exceptions (try-catch-throw).
  16   */
  17  
  18  
  19  if (!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR);
  20  define('ADODB_ERROR_HANDLER','adodb_throw');
  21  
  22  class ADODB_Exception extends Exception {
  23  var $dbms;
  24  var $fn;
  25  var $sql = '';
  26  var $params = '';
  27  var $host = '';
  28  var $database = '';
  29  
  30  	function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
  31  	 {
  32  	 	 switch($fn) {
  33  	 	 case 'EXECUTE':
  34  	 	 	 $this->sql = is_array($p1) ? $p1[0] : $p1;
  35  	 	 	 $this->params = $p2;
  36  	 	 	 $s = "$dbms error: [$errno: $errmsg] in $fn(\"$this->sql\")";
  37  	 	 	 break;
  38  
  39  	 	 case 'PCONNECT':
  40  	 	 case 'CONNECT':
  41  	 	 	 $user = $thisConnection->user;
  42  	 	 	 $s = "$dbms error: [$errno: $errmsg] in $fn($p1, '$user', '****', $p2)";
  43  	 	 	 break;
  44  	 	 default:
  45  	 	 	 $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)";
  46  	 	 	 break;
  47  	 	 }
  48  
  49  	 	 $this->dbms = $dbms;
  50  	 	 if ($thisConnection) {
  51  	 	 	 $this->host = $thisConnection->host;
  52  	 	 	 $this->database = $thisConnection->database;
  53  	 	 }
  54  	 	 $this->fn = $fn;
  55  	 	 $this->msg = $errmsg;
  56  
  57  	 	 if (!is_numeric($errno)) $errno = -1;
  58  	 	 parent::__construct($s,$errno);
  59  	 }
  60  }
  61  
  62  /**
  63  * Default Error Handler. This will be called with the following params
  64  *
  65  * @param $dbms	 	 the RDBMS you are connecting to
  66  * @param $fn	 	 the name of the calling function (in uppercase)
  67  * @param $errno	 	 the native error number from the database
  68  * @param $errmsg	 the native error msg from the database
  69  * @param $p1	 	 $fn specific parameter - see below
  70  * @param $P2	 	 $fn specific parameter - see below
  71  */
  72  
  73  function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
  74  {
  75  global $ADODB_EXCEPTION;
  76  
  77  	 if (error_reporting() == 0) return; // obey @ protocol
  78  	 if (is_string($ADODB_EXCEPTION)) $errfn = $ADODB_EXCEPTION;
  79  	 else $errfn = 'ADODB_EXCEPTION';
  80  	 throw new $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection);
  81  }