adodb-errorpear.inc.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * @version v5.20.17 31-Mar-2020
  4. * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
  5. * @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
  6. * Released under both BSD license and Lesser GPL library license.
  7. Whenever there is any discrepancy between the two licenses,
  8. the BSD license will take precedence.
  9. *
  10. * Set tabs to 4 for best viewing.
  11. *
  12. * Latest version is available at http://adodb.org/
  13. *
  14. */
  15. include_once('PEAR.php');
  16. if (!defined('ADODB_ERROR_HANDLER')) define('ADODB_ERROR_HANDLER','ADODB_Error_PEAR');
  17. /*
  18. * Enabled the following if you want to terminate scripts when an error occurs
  19. */
  20. //PEAR::setErrorHandling (PEAR_ERROR_DIE);
  21. /*
  22. * Name of the PEAR_Error derived class to call.
  23. */
  24. if (!defined('ADODB_PEAR_ERROR_CLASS')) define('ADODB_PEAR_ERROR_CLASS','PEAR_Error');
  25. /*
  26. * Store the last PEAR_Error object here
  27. */
  28. global $ADODB_Last_PEAR_Error; $ADODB_Last_PEAR_Error = false;
  29. /**
  30. * Error Handler with PEAR support. This will be called with the following params
  31. *
  32. * @param $dbms the RDBMS you are connecting to
  33. * @param $fn the name of the calling function (in uppercase)
  34. * @param $errno the native error number from the database
  35. * @param $errmsg the native error msg from the database
  36. * @param $p1 $fn specific parameter - see below
  37. * @param $P2 $fn specific parameter - see below
  38. */
  39. function ADODB_Error_PEAR($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false)
  40. {
  41. global $ADODB_Last_PEAR_Error;
  42. if (error_reporting() == 0) return; // obey @ protocol
  43. switch($fn) {
  44. case 'EXECUTE':
  45. $sql = $p1;
  46. $inputparams = $p2;
  47. $s = "$dbms error: [$errno: $errmsg] in $fn(\"$sql\")";
  48. break;
  49. case 'PCONNECT':
  50. case 'CONNECT':
  51. $host = $p1;
  52. $database = $p2;
  53. $s = "$dbms error: [$errno: $errmsg] in $fn('$host', ?, ?, '$database')";
  54. break;
  55. default:
  56. $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)";
  57. break;
  58. }
  59. $class = ADODB_PEAR_ERROR_CLASS;
  60. $ADODB_Last_PEAR_Error = new $class($s, $errno,
  61. $GLOBALS['_PEAR_default_error_mode'],
  62. $GLOBALS['_PEAR_default_error_options'],
  63. $errmsg);
  64. //print "<p>!$s</p>";
  65. }
  66. /**
  67. * Returns last PEAR_Error object. This error might be for an error that
  68. * occured several sql statements ago.
  69. */
  70. function ADODB_PEAR_Error()
  71. {
  72. global $ADODB_Last_PEAR_Error;
  73. return $ADODB_Last_PEAR_Error;
  74. }