note 96173 added to class.pdo
| From: | Dsiembab01 at google dot com | Date: | Fri, 12 Feb 2010 11:24:05 +0000 |
| Subject: | note 96173 added to class.pdo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165900@lists.php.net to get a copy of this message | ||
so would this be outrageous
<?php
class Db_Pdo extends PDO
{
public $dsnStruct = array(
'mysql' => array(
'dsnIndexes' => array('unix_socket')
),
'pgsql' => array(
'dsnIndexes' => array('user', 'password'),
'dsnOptions' => array('dsnDelimeter' => ' '),
),
'sqlite' => array()
);
public $dsnIndexes = array('host'=>'', 'port'=>
'', 'dbname'=>'');
public $dsnDelimeter = ';';
public $type = 'mysql';
public $required = array('user', 'pass');
public function __construct($params)
{
if(is_array($params))
{
$this->setOptions($params['type']);
$dsn = $this->makeDsn($params);
}
}
public function setOptions($type)
{
if(array_key_exists($type, $this->dsnStruct))
{
$this->type = $type;
$options = $this->dsnStruct[$type];
if(isset($options['dsnOptions'])){
foreach($options as $k => $v){
$property = 'set' . ucfirst($k);
$this->set{$property}($v);
}
}
if(isset($options['dsnIndexes']))
{
foreach ($options['dsnIndexes'] as $k => $v)
{
if(is_int($k))
{
$k = $v;
$v = null;
}
$this->dsnIndexes[$k] = $v;
}
}else{
$this->dsnIndexes = array('file' => '');
}
}
}
public function makeDsn($array)
{
$dsnCheck = array_intersect_key($array, $this->dsnIndexes);
$dsnString = $this->type .':';
if(isset($dsnCheck['file']))
{
$dsnString .= $dsnCheck['file'];
$array = null;
}else{
foreach($dsnCheck as $key => $value)
{
$dsnString .= $key . '=' . $value . $this->dsnDelimeter;
}
}
$dsn = rtrim($dsnString, $this->dsnDelimeter);
parent::__construct($dsn, $array['user'], $array['pass']);
}
public function setDsnDelimeter($value)
{
$this->dsnDelimeter = $value;
}
}
?>
----
Server IP: 192.41.40.227
Probable Submitter: 24.38.172.80
----
Manual Page -- http://www.php.net/manual/en/class.pdo.php
Edit -- https://master.php.net/note/edit/96173
Del: integrated -- https://master.php.net/note/delete/96173/integrated
Del: useless -- https://master.php.net/note/delete/96173/useless
Del: bad code -- https://master.php.net/note/delete/96173/bad+code
Del: spam -- https://master.php.net/note/delete/96173/spam
Del: non-english -- https://master.php.net/note/delete/96173/non-english
Del: in docs -- https://master.php.net/note/delete/96173/in+docs
Del: other reasons-- https://master.php.net/note/delete/96173
Reject -- https://master.php.net/note/reject/96173
Search -- https://master.php.net/manage/user-notes.php