Source for file set_error_handler.php

Documentation is available at set_error_handler.php

  1. <?php
  2. /**
  3. * SetErrorHandler Example
  4. *
  5. * This example show how to set an error handler for AbstractDB.
  6. * @package AbstractDB
  7. * @author Pacific-Cybersoft
  8. * @copyright (C) 2005 Pacific-Cybersoft. All Rights Reserved.
  9. * @version v 1.0.2
  10. * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
  11. */
  12.  
  13. /**
  14. * Include the AbstractDB main class.
  15. */
  16. include("../abstractdb.class.php");
  17.  
  18. function ExampleErrorHandler($source, $error)
  19. {
  20. // Do something with the info.
  21. // $source will be a copy of the AbstractDB object.
  22. print_r($source);
  23. // $error will be an associative array containing error scope and message.
  24. echo($error["Scope"] . " - " . $error["Message"]);
  25. }
  26.  
  27. // Instatiate AbstractDB
  28. $db = new AbstractDB(array("ConnectionString"=>"mysql://username:password@localhost/mydatabase"));
  29. // Set the error handler
  30. $db->SetErrorHandler("ExampleErrorHandler") or die($db->GetLastError());
  31. // Now if we execute a bad query or whenever an error occurs, ExampleErrorHandler will be called.
  32. $db->Query("SELECT NonExistentColumn from BadTableName");
  33. // Always good practice to close AbstractDB at the end of each script.
  34. $db->Close();
  35. ?>

Documentation generated on Wed, 16 Mar 2005 23:17:29 +1100 by phpDocumentor 1.3.0RC3