Skip to content

Instantly share code, notes, and snippets.

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