Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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  	 	 	 $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)";
  49  	 	 	 break;
  50  	 	 }
  51  
  52  	 	 $this->dbms = $dbms;
  53  	 	 if ($thisConnection) {
  54  	 	 	 $this->host = $thisConnection->host;
  55  	 	 	 $this->database = $thisConnection->database;
  56  	 	 }
  57  	 	 $this->fn = $fn;
  58  	 	 $this->msg = $errmsg;
  59  
  60  	 	 if (!is_numeric($errno)) $errno = -1;
  61  	 	 parent::__construct($s,$errno);
  62  	 }
  63  }
  64  
  65  /**
  66  * Default Error Handler.
  67  *
  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
  74  */
  75  
  76  function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
  77  {
  78  global $ADODB_EXCEPTION;
  79  
  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);
  84  }