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); } // }}}