File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ public function __construct(array $config)
4141 $ this ->connection = $ this ->createConnection ($ dsn , $ config , $ options );
4242
4343 // Select database
44- $ this ->db = $ this ->connection ->selectDatabase ($ this ->getDatabaseDsn ($ dsn ));
44+ $ this ->db = $ this ->connection ->selectDatabase ($ this ->getDatabaseDsn ($ dsn, $ config [ ' database ' ] ));
4545
4646 $ this ->useDefaultPostProcessor ();
4747
@@ -190,7 +190,7 @@ protected function getHostDsn(array $config)
190190 }
191191
192192 // Check if we want to authenticate against a specific database.
193- $ auth_database = isset ($ config ['database ' ]) && !empty ($ config ['database ' ]) ? $ config ['database ' ] : null ;
193+ $ auth_database = isset ($ config ['options ' ]) && !empty ($ config ['options ' ][ ' database ' ]) ? $ config[ ' options ' ] ['database ' ] : null ;
194194 return 'mongodb:// ' . implode (', ' , $ hosts ) . ($ auth_database ? '/ ' . $ auth_database : '' );
195195 }
196196
@@ -199,9 +199,10 @@ protected function getHostDsn(array $config)
199199 * @param string $dsn
200200 * @return string
201201 */
202- protected function getDatabaseDsn ($ dsn )
202+ protected function getDatabaseDsn ($ dsn, $ database )
203203 {
204- return trim (parse_url ($ dsn , PHP_URL_PATH ), '/ ' );
204+ $ dsnDatabase = trim (parse_url ($ dsn , PHP_URL_PATH ), '/ ' );
205+ return $ dsnDatabase ?:$ database ;
205206 }
206207
207208 /**
You can’t perform that action at this time.
0 commit comments