Skip to content

Commit

Permalink
Fixes mongodb#17
Browse files Browse the repository at this point in the history
  • Loading branch information
mnphpexpert committed Aug 7, 2013
1 parent 8ca7403 commit 449f43c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Jenssegers/Mongodb/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,26 @@ protected function getDsn(array $config)
// Treat host option as array of hosts
$hosts = is_array($config['host']) ? $config['host'] : array($config['host']);

// Add ports to hosts
foreach ($hosts as &$host)
{
if (isset($config['username']) and isset($config['password']))
{
$host = "{$username}:{$password}@{$host}";
}

if (isset($config['port']))
{
$host = "{$host}:{$port}";
}
}

return "mongodb://" . implode(',', $hosts) . "/{$database}";
// Credentials
if (isset($config['username']) and isset($config['password']))
{
$credentials = "{$username}:{$password}@";
}
else
{
$credentials = '';
}

return "mongodb://{$credentials}" . implode(',', $hosts) . "/{$database}";
}

/**
Expand Down

0 comments on commit 449f43c

Please sign in to comment.