From 449f43c6a2c4fec7a246b894ad7c5747d2b4163c Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Wed, 7 Aug 2013 23:12:19 +0200 Subject: [PATCH] Fixes #17 --- src/Jenssegers/Mongodb/Connection.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Jenssegers/Mongodb/Connection.php b/src/Jenssegers/Mongodb/Connection.php index 733d2bbdf..9a7749351 100644 --- a/src/Jenssegers/Mongodb/Connection.php +++ b/src/Jenssegers/Mongodb/Connection.php @@ -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}"; } /**