Created
April 13, 2018 08:36
-
-
Save TheAnarchoX/57d6b08bf4ec7ca756d1160dd9f642a7 to your computer and use it in GitHub Desktop.
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