Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use PDO;
- Class SafePDO extends PDO {
- private $server = "";
- private $username = "";
- private $pass = "";
- private $database = "";
- public static function exception_handler($exception) {
- die('Uncaught exception: ' . $exception->getMessage());
- }
- public function __construct() {
- // Temporarily change the PHP exception handler while we . . .
- set_exception_handler(array(__CLASS__, 'exception_handler'));
- // . . . create a PDO object
- $dsn = 'mysql:host=' . $this->server . ';dbname=' . $this->database;
- parent::__construct($dsn, $this->username, $this->pass);
- // Change the exception handler back to whatever it was before
- restore_exception_handler();
- }
- }
- ?>
Add Comment
Please, Sign In to add comment