adodb-errorhandler.inc.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // added Claudio Bustos clbustos#entelchile.net
  16. if (!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR);
  17. if (!defined('ADODB_ERROR_HANDLER')) define('ADODB_ERROR_HANDLER','ADODB_Error_Handler');
  18. /**
  19. * Default Error Handler. This will be called with the following params
  20. *
  21. * @param $dbms the RDBMS you are connecting to
  22. * @param $fn the name of the calling function (in uppercase)
  23. * @param $errno the native error number from the database
  24. * @param $errmsg the native error msg from the database
  25. * @param $p1 $fn specific parameter - see below
  26. * @param $p2 $fn specific parameter - see below
  27. * @param $thisConn $current connection object - can be false if no connection object created
  28. */
  29. function ADODB_Error_Handler($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection)
  30. {
  31. if (error_reporting() == 0) return; // obey @ protocol
  32. switch($fn) {
  33. case 'EXECUTE':
  34. $sql = $p1;
  35. $inputparams = $p2;
  36. $s = "$dbms error: [$errno: $errmsg] in $fn(\"$sql\")\n";
  37. break;
  38. case 'PCONNECT':
  39. case 'CONNECT':
  40. $host = $p1;
  41. $database = $p2;
  42. $s = "$dbms error: [$errno: $errmsg] in $fn($host, '****', '****', $database)\n";
  43. break;
  44. default:
  45. $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)\n";
  46. break;
  47. }
  48. /*
  49. * Log connection error somewhere
  50. * 0 message is sent to PHP's system logger, using the Operating System's system
  51. * logging mechanism or a file, depending on what the error_log configuration
  52. * directive is set to.
  53. * 1 message is sent by email to the address in the destination parameter.
  54. * This is the only message type where the fourth parameter, extra_headers is used.
  55. * This message type uses the same internal function as mail() does.
  56. * 2 message is sent through the PHP debugging connection.
  57. * This option is only available if remote debugging has been enabled.
  58. * In this case, the destination parameter specifies the host name or IP address
  59. * and optionally, port number, of the socket receiving the debug information.
  60. * 3 message is appended to the file destination
  61. */
  62. if (defined('ADODB_ERROR_LOG_TYPE')) {
  63. $t = date('Y-m-d H:i:s');
  64. if (defined('ADODB_ERROR_LOG_DEST'))
  65. error_log("($t) $s", ADODB_ERROR_LOG_TYPE, ADODB_ERROR_LOG_DEST);
  66. else
  67. error_log("($t) $s", ADODB_ERROR_LOG_TYPE);
  68. }
  69. //print "<p>$s</p>";
  70. trigger_error($s,ADODB_ERROR_HANDLER_TYPE);
  71. }