DBEventHandler.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /** @package verysimple::DB::Reflection */
  3. /** import supporting libraries */
  4. require_once('verysimple/DB/DatabaseException.php');
  5. define("DBH_LOG_NONE",1);
  6. define("DBH_LOG_INFO",2);
  7. define("DBH_LOG_DEBUG",4);
  8. define("DBH_LOG_QUERY",8);
  9. define("DBH_LOG_WARNING",16);
  10. define("DBH_LOG_ERROR",32);
  11. /**
  12. * DBEventHandler is an optional parameter that can be used to hook into events in the
  13. * DAO system for intercepting, debugging and observing
  14. *
  15. * @package verysimple::DB::Reflection
  16. * @author Jason Hinkle
  17. * @copyright 1997-2007 VerySimple, Inc.
  18. * @license http://www.gnu.org/licenses/lgpl.html LGPL
  19. * @version 1.0
  20. */
  21. class DBEventHandler
  22. {
  23. public $LogLevel;
  24. function __construct($level = DBH_LOG_NONE)
  25. {
  26. $this->LogLevel = $level;
  27. }
  28. /**
  29. * Called by DB objects to report logging information
  30. *
  31. * @access public
  32. * @param int $level
  33. * @param string $message
  34. * @param string $data
  35. */
  36. function Log($level,$message, $data = "")
  37. {
  38. $data = $data != "" ? ": $data" : "";
  39. switch ($level)
  40. {
  41. case DBH_LOG_DEBUG:
  42. if ($this->LogLevel & DBH_LOG_DEBUG) print "<pre style='color: silver;'>$message</pre>\r\n";
  43. break;
  44. case DBH_LOG_INFO:
  45. if ($this->LogLevel & DBH_LOG_INFO) print "<pre style='color: blue;'>$message $data</pre>\r\n";
  46. break;
  47. case DBH_LOG_QUERY:
  48. if ($this->LogLevel & DBH_LOG_QUERY) print "<pre style='color: green;'>$message $data</pre>\r\n";
  49. break;
  50. case DBH_LOG_WARNING:
  51. if ($this->LogLevel & DBH_LOG_WARNING) print "<pre style='color: orange;'>$message $data</pre>\r\n";
  52. break;
  53. case DBH_LOG_ERROR:
  54. if ($this->LogLevel & DBH_LOG_ERROR) print "<pre style='color: red;'>$message $data</pre>\r\n";
  55. break;
  56. }
  57. }
  58. /**
  59. * Called by DB objects when a critical error occurs
  60. *
  61. * @access public
  62. * @param int $code unique numerical identifier for error
  63. * @param string $message human-readable error
  64. * @param string $data any additional information that may help with debugging
  65. */
  66. function Crash($code, $message = "", $data = "")
  67. {
  68. throw new DatabaseException($message,$code,$data);
  69. }
  70. }
  71. ?>