From e40a0e52ab625829a6aa2821e5de0df063ef24c9 Mon Sep 17 00:00:00 2001 From: Lukas Smith Date: Sun, 23 Mar 2003 17:24:05 +0000 Subject: [PATCH] improvements to getDSN and setDSN git-svn-id: http://svn.php.net/repository/pear/packages/MDB/trunk@120991 c90b9560-bf6c-de11-be94-00142212c4b1 --- MDB.php | 1 - MDB/Common.php | 30 ++++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/MDB.php b/MDB.php index 42b1a8a..c98e5d4 100644 --- a/MDB.php +++ b/MDB.php @@ -325,7 +325,6 @@ function &connect($dsn, $options = FALSE) $db->captureDebugOutput(TRUE); } if(isset($dsninfo['database'])) { - $db->setDatabase($dsninfo['database']); $err = $db->connect(); if (MDB::isError($err)) { $dsn = $db->getDSN(); diff --git a/MDB/Common.php b/MDB/Common.php index 9dbc19a..bb7c422 100644 --- a/MDB/Common.php +++ b/MDB/Common.php @@ -737,6 +737,9 @@ function setDSN($dsn) if(isset($dsninfo['password'])) { $this->password = $dsninfo['password']; } + if(isset($dsninfo['database'])) { + $this->database_name = $dsninfo['database']; + } return(MDB_OK); } @@ -746,15 +749,30 @@ function setDSN($dsn) /** * return the DSN as a string * - * @return string DSN + * @param string $type type to return + * @return mixed DSN in the chosen type * @access public */ - function getDSN() + function getDSN($type = 'string') { - return($this->phptype.'://'.$this->user.':' - .$this->password.'@'.$this->host - .(isset($this->port) ? (':'.$this->port) : '') - .'/'.$this->database_name); + switch($type) { + case 'array': + $dsn = array( + 'phptype' => $this->phptype, + 'username' => $this->user, + 'password' => $this->password, + 'hostspec' => $this->host, + 'database' => $this->database_name + ); + break; + default: + $dsn = $this->phptype.'://'.$this->user.':' + .$this->password.'@'.$this->host + .(isset($this->port) ? (':'.$this->port) : '') + .'/'.$this->database_name; + break; + } + return($dsn); } // }}}