Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class mysqlDatabase extends dBase { /* ... code here ... */ }
- $DB = mysqlDatabase::instance();
- $DB->execute("SELECT * FROM foobar WHERE"); // Should throw errors, 'WHERE clause is empty'
- // What happens here?
- // Personally, I would do something like this:
- class Logger {
- function Log($message) {
- // Log $message
- }
- }
- function defaultExceptionHandler($E) {
- // I would actually probably try to throw up a pretty page, if I had the time
- header('HTTP/1.1 500'); // Set internal service error header
- print "An error has occurred: " . $E->getMessage();
- die();
- }
- class DBase {
- function execute($query) {
- try {
- $this->_dbh->exec($query);
- } catch PDOExeption $E {
- Logger::Log($E->getMessage(0);
- throw $E;
- }
- }
- }
- // Usage example:
- $DB->execute("I am not a valid SQL query");
- // What happens now is Logger::Log() got called
- // Since I didn't catch the exception, DefaultExceptionHandler() was called which prints a message and dies.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement