HDFilmMaker2112 Posted May 31, 2012 Share Posted May 31, 2012 This is the first time I wrote a class, so I want to make sure this is right. Under "class SafePDO_errordisplay extends SafePDO" am I using "parent::__construct($dsn, $username, $password, $driver_options);" correctly? It should be sending the connection data to SafePDO to start the connection. The errordisplay class is there to catch any error on the connection. 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(); } } class SafePDO_errordisplay extends SafePDO { public function connect_db($dsn, $username='', $password='', $driver_options=array()){ parent::__construct($dsn, $username, $password, $driver_options); try { $DB = new SafePDO($dsn, $user, $password, $driver_options); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } } } // Connect to the database - So my other coders only need to know the dbname to connect, not the MySQL log-in details. function SafePDOPersist($dbname){ $DB = new SafePDO_errordisplay("mysql:host=localhost;dbname=$dbname", $DBusername, $DBpassword, array(PDO::ATTR_PERSISTENT => true)); } function SafePDOCOE($dbname){ $DB = new SafePDO_errordisplay("mysql:host=localhost;dbname=$dbname", $DBusername, $DBpassword); } Quote Link to comment https://forums.phpfreaks.com/topic/263414-class-help/ Share on other sites More sharing options...
trq Posted May 31, 2012 Share Posted May 31, 2012 Have you tried actually using these classes / functions? Sorry, but they make little sense. Quote Link to comment https://forums.phpfreaks.com/topic/263414-class-help/#findComment-1350035 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.