adodb-exceptions.inc.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. * Exception-handling code using PHP5 exceptions (try-catch-throw).
  15. */
  16. if (!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR);
  17. define('ADODB_ERROR_HANDLER','adodb_throw');
  18. class ADODB_Exception extends Exception {
  19. var $dbms;
  20. var $fn;
  21. var $sql = '';
  22. var $params = '';
  23. var $host = '';
  24. var $database = '';
  25. function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
  26. {
  27. switch($fn) {
  28. case 'EXECUTE':
  29. $this->sql = is_array($p1) ? $p1[0] : $p1;
  30. $this->params = $p2;
  31. $s = "$dbms error: [$errno: $errmsg] in $fn(\"$this->sql\")";
  32. break;
  33. case 'PCONNECT':
  34. case 'CONNECT':
  35. $user = $thisConnection->user;
  36. $s = "$dbms error: [$errno: $errmsg] in $fn($p1, '$user', '****', $p2)";
  37. break;
  38. default:
  39. $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)";
  40. break;
  41. }
  42. $this->dbms = $dbms;
  43. if ($thisConnection) {
  44. $this->host = $thisConnection->host;
  45. $this->database = $thisConnection->database;
  46. }
  47. $this->fn = $fn;
  48. $this->msg = $errmsg;
  49. if (!is_numeric($errno)) $errno = -1;
  50. parent::__construct($s,$errno);
  51. }
  52. }
  53. /**
  54. * Default Error Handler. This will be called with the following params
  55. *
  56. * @param $dbms the RDBMS you are connecting to
  57. * @param $fn the name of the calling function (in uppercase)
  58. * @param $errno the native error number from the database
  59. * @param $errmsg the native error msg from the database
  60. * @param $p1 $fn specific parameter - see below
  61. * @param $P2 $fn specific parameter - see below
  62. */
  63. function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
  64. {
  65. global $ADODB_EXCEPTION;
  66. if (error_reporting() == 0) return; // obey @ protocol
  67. if (is_string($ADODB_EXCEPTION)) $errfn = $ADODB_EXCEPTION;
  68. else $errfn = 'ADODB_EXCEPTION';
  69. throw new $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection);
  70. }