note 110709 deleted from class.pdo by tularis

From: Date: Mon, 26 Nov 2012 19:17:02 +0000
Subject: note 110709 deleted from class.pdo by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192153@lists.php.net to get a copy of this message
Note Submitter: pedja at supurovic dot net ---- Here is small extension of PDO that introduces two new properties: driver and driver_parameters. The first one keeps info about driver used for connection (thus informing which database is used) and the second keeps all other parameters sent to driver. This could be helpful when PDO is used in multidatabase environment and there is need to adjust some code regarding database type. class cPDO extends PDO { private $driver; private $driver_parameters; public function __construct($p_dsn, $p_username='', $p_password='', $p_driver_options=Array() ) { $m_parsed_dsn = parse_url ($p_dsn); $this->driver=strtolower ($m_parsed_dsn['scheme']); $m_params = explode (';', $m_parsed_dsn['path']); foreach ($m_params as $m_key => $m_item) { if ( ($m_key == 0) && ($this->driver == 'sqlite') ) { $this->driver_parameters['host'] = trim ($m_item); } else { $m_split = explode ('=', trim ($m_item)); $this->driver_parameters[trim ($m_split[0])] = trim ($m_split[1]); } } parent::__construct( $p_dsn, $p_username, $p_password, $p_driver_options ); } public function __get($p_name) { return $this->{$p_name}; } }

« previous php.notes (#192153) next »