note 111850 deleted from pdo.connections by aharvey
| From: | aharvey@php.net | Date: | Mon, 08 Apr 2013 01:24:00 +0000 |
| Subject: | note 111850 deleted from pdo.connections by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194377@lists.php.net to get a copy of this message | ||
Note Submitter: Terrence LP
----
Correction to post #1 - there is a syntax error on like 6 that has been corrected below.
<?php
class SafePDO extends PDO {
public static function exception_handler($exception) {
// Output the exception details
print('Uncaught exception: '. $exception->getMessage());
}
public function __construct($dsn, $username='webaccess',
$password='Terrence1', $driver_options=array(
PDO::ATTR_PERSISTENT => true
)) {
// Temporarily change the PHP exception handler while we . . .
set_exception_handler(array(__CLASS__, 'exception_handler'));
// . . . create a PDO object
parent::__construct($dsn, $username, $password, $driver_options);
// Change the exception handler back to whatever it was before
restore_exception_handler();
}
}
// Connect to the database with defined constants
$dbh = new SafePDO(PDO_DSN, PDO_USER, PDO_PASSWORD);
?>