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]

   1  <?php
   2  /**
   3   * Error Handler with PEAR support.
   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  include_once('PEAR.php');
  23  
  24  if (!defined('ADODB_ERROR_HANDLER')) define('ADODB_ERROR_HANDLER','ADODB_Error_PEAR');
  25  
  26  /*
  27  * Enabled the following if you want to terminate scripts when an error occurs
  28  */
  29  //PEAR::setErrorHandling (PEAR_ERROR_DIE);
  30  
  31  /*
  32  * Name of the PEAR_Error derived class to call.
  33  */
  34  if (!defined('ADODB_PEAR_ERROR_CLASS')) define('ADODB_PEAR_ERROR_CLASS','PEAR_Error');
  35  
  36  /*
  37  * Store the last PEAR_Error object here
  38  */
  39  global $ADODB_Last_PEAR_Error; $ADODB_Last_PEAR_Error = false;
  40  
  41    /**
  42  * Error Handler with PEAR support. This will be called with the following params
  43  *
  44  * @param $dbms	 	 the RDBMS you are connecting to
  45  * @param $fn	 	 the name of the calling function (in uppercase)
  46  * @param $errno	 	 the native error number from the database
  47  * @param $errmsg	 the native error msg from the database
  48  * @param $p1	 	 $fn specific parameter - see below
  49  * @param $P2	 	 $fn specific parameter - see below
  50  	 */
  51  function ADODB_Error_PEAR($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false)
  52  {
  53  global $ADODB_Last_PEAR_Error;
  54  
  55  	 if (error_reporting() == 0) return; // obey @ protocol
  56  	 switch($fn) {
  57  	 case 'EXECUTE':
  58  	 	 $sql = $p1;
  59  	 	 $inputparams = $p2;
  60  
  61  	 	 $s = "$dbms error: [$errno: $errmsg] in $fn(\"$sql\")";
  62  	 	 break;
  63  
  64  	 case 'PCONNECT':
  65  	 case 'CONNECT':
  66  	 	 $host = $p1;
  67  	 	 $database = $p2;
  68  
  69  	 	 $s = "$dbms error: [$errno: $errmsg] in $fn('$host', ?, ?, '$database')";
  70  	 	 break;
  71  
  72  	 default:
  73  	 	 $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)";
  74  	 	 break;
  75  	 }
  76  
  77  	 $class = ADODB_PEAR_ERROR_CLASS;
  78  	 $ADODB_Last_PEAR_Error = new $class($s, $errno,
  79  	 	 $GLOBALS['_PEAR_default_error_mode'],
  80  	 	 $GLOBALS['_PEAR_default_error_options'],
  81  	 	 $errmsg);
  82  
  83  	 //print "<p>!$s</p>";
  84  }
  85  
  86  /**
  87  * Returns last PEAR_Error object. This error might be for an error that
  88  * occurred several sql statements ago.
  89  */
  90  function ADODB_PEAR_Error()
  91  {
  92  global $ADODB_Last_PEAR_Error;
  93  
  94  	 return $ADODB_Last_PEAR_Error;
  95  }