Skip to content

Commit 929120f

Browse files
committed
bugfix: failover to database configuration values if no ability to get database from DSN
1 parent 76a5dbc commit 929120f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Jenssegers/Mongodb/Connection.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,15 @@ protected function getHostDsn(array $config)
195195
}
196196

197197
/**
198-
* Get database name from DSN string.
198+
* Get database name from DSN string, if there is no database in DSN path - returns back $database argument.
199199
* @param string $dsn
200+
* @param $database
200201
* @return string
201202
*/
202203
protected function getDatabaseDsn($dsn, $database)
203204
{
204205
$dsnDatabase = trim(parse_url($dsn, PHP_URL_PATH), '/');
205-
return $dsnDatabase?:$database;
206+
return trim($dsnDatabase) ? $dsnDatabase : $database;
206207
}
207208

208209
/**

0 commit comments

Comments
 (0)