note 94100 added to pdo.connections

From: Date: Fri, 16 Oct 2009 10:40:17 +0000
Subject: note 94100 added to pdo.connections
Groups: php.notes 
Request: Send a blank email to php-notes+get-161801@lists.php.net to get a copy of this message
To avoid exposing your connection details should you fail to remember to catch any exception thrown by the PDO constructor you can use the following class to implicitly change the exception handler temporarily. <?php Class SafePDO extends PDO { public static function exception_handler($exception) { // Output the exception details die('Uncaught exception: ', $exception->getMessage()); } public function __construct($dsn, $username='', $password='', $driver_options=array()) { // 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); ?> ---- Server IP: 92.48.74.199 Probable Submitter: 87.246.75.116 ---- Manual Page -- http://www.php.net/manual/en/pdo.connections.php Edit -- https://master.php.net/note/edit/94100 Del: integrated -- https://master.php.net/note/delete/94100/integrated Del: useless -- https://master.php.net/note/delete/94100/useless Del: bad code -- https://master.php.net/note/delete/94100/bad+code Del: spam -- https://master.php.net/note/delete/94100/spam Del: non-english -- https://master.php.net/note/delete/94100/non-english Del: in docs -- https://master.php.net/note/delete/94100/in+docs Del: other reasons-- https://master.php.net/note/delete/94100 Reject -- https://master.php.net/note/reject/94100 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161801) next »