Created
December 13, 2014 04:49
-
-
Save ShawnAbshire/674f67604bec706c930b to your computer and use it in GitHub Desktop.
SafePDO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment