Skip to content

Commit f575d18

Browse files
committed
Fixes #17
1 parent 2760d04 commit f575d18

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Diff for: src/Jenssegers/Mongodb/Connection.php

+12-6
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,26 @@ protected function getDsn(array $config)
111111
// Treat host option as array of hosts
112112
$hosts = is_array($config['host']) ? $config['host'] : array($config['host']);
113113

114+
// Add ports to hosts
114115
foreach ($hosts as &$host)
115116
{
116-
if (isset($config['username']) and isset($config['password']))
117-
{
118-
$host = "{$username}:{$password}@{$host}";
119-
}
120-
121117
if (isset($config['port']))
122118
{
123119
$host = "{$host}:{$port}";
124120
}
125121
}
126122

127-
return "mongodb://" . implode(',', $hosts) . "/{$database}";
123+
// Credentials
124+
if (isset($config['username']) and isset($config['password']))
125+
{
126+
$credentials = "{$username}:{$password}@";
127+
}
128+
else
129+
{
130+
$credentials = '';
131+
}
132+
133+
return "mongodb://{$credentials}" . implode(',', $hosts) . "/{$database}";
128134
}
129135

130136
/**

0 commit comments

Comments
 (0)