Skip to content

Commit

Permalink
improvements to getDSN and setDSN
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.php.net/repository/pear/packages/MDB/trunk@120991 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Lukas Smith committed Mar 23, 2003
1 parent 19bad36 commit e40a0e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
1 change: 0 additions & 1 deletion MDB.php
Expand Up @@ -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();
Expand Down
30 changes: 24 additions & 6 deletions MDB/Common.php
Expand Up @@ -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);
}

Expand All @@ -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);
}

// }}}
Expand Down

0 comments on commit e40a0e5

Please sign in to comment.