Guest User

Untitled

a guest
Apr 21st, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. <?php
  2. use PDO;
  3. Class SafePDO extends PDO {
  4. private $server = "";
  5. private $username = "";
  6. private $pass = "";
  7. private $database = "";
  8. public static function exception_handler($exception) {
  9. die('Uncaught exception: ' . $exception->getMessage());
  10. }
  11. public function __construct() {
  12. // Temporarily change the PHP exception handler while we . . .
  13. set_exception_handler(array(__CLASS__, 'exception_handler'));
  14. // . . . create a PDO object
  15. $dsn = 'mysql:host=' . $this->server . ';dbname=' . $this->database;
  16. parent::__construct($dsn, $this->username, $this->pass);
  17. // Change the exception handler back to whatever it was before
  18. restore_exception_handler();
  19. }
  20. }
  21. ?>
Add Comment
Please, Sign In to add comment