Commit 76a5dbc8 authored by Oleg Khimich's avatar Oleg Khimich

bugfix: failover to database configuration values if no ability to get database from DSN

parent 068a0af2
...@@ -41,7 +41,7 @@ class Connection extends BaseConnection ...@@ -41,7 +41,7 @@ class Connection extends BaseConnection
$this->connection = $this->createConnection($dsn, $config, $options); $this->connection = $this->createConnection($dsn, $config, $options);
// Select database // Select database
$this->db = $this->connection->selectDatabase($this->getDatabaseDsn($dsn)); $this->db = $this->connection->selectDatabase($this->getDatabaseDsn($dsn, $config['database']));
$this->useDefaultPostProcessor(); $this->useDefaultPostProcessor();
...@@ -190,7 +190,7 @@ class Connection extends BaseConnection ...@@ -190,7 +190,7 @@ class Connection extends BaseConnection
} }
// Check if we want to authenticate against a specific database. // Check if we want to authenticate against a specific database.
$auth_database = isset($config['database']) && !empty($config['database']) ? $config['database'] : null; $auth_database = isset($config['options']) && !empty($config['options']['database']) ? $config['options']['database'] : null;
return 'mongodb://' . implode(',', $hosts) . ($auth_database ? '/' . $auth_database : ''); return 'mongodb://' . implode(',', $hosts) . ($auth_database ? '/' . $auth_database : '');
} }
...@@ -199,9 +199,10 @@ class Connection extends BaseConnection ...@@ -199,9 +199,10 @@ class Connection extends BaseConnection
* @param string $dsn * @param string $dsn
* @return string * @return string
*/ */
protected function getDatabaseDsn($dsn) protected function getDatabaseDsn($dsn, $database)
{ {
return trim(parse_url($dsn, PHP_URL_PATH), '/'); $dsnDatabase = trim(parse_url($dsn, PHP_URL_PATH), '/');
return $dsnDatabase?:$database;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment