Commit e1e95a50 authored by Oleg Khimich's avatar Oleg Khimich

get database from DSN string

parent 459d7e82
...@@ -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($config['database']); $this->db = $this->connection->selectDatabase($this->getDatabaseDsn($dsn));
$this->useDefaultPostProcessor(); $this->useDefaultPostProcessor();
...@@ -191,10 +191,19 @@ class Connection extends BaseConnection ...@@ -191,10 +191,19 @@ 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['options']) && !empty($config['options']['database']) ? $config['options']['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 : '');
} }
/**
* Get database name from DSN string.
* @param string $dsn
* @return string
*/
protected function getDatabaseDsn($dsn)
{
return trim(parse_url($dsn, PHP_URL_PATH), '/');
}
/** /**
* Create a DSN string from a configuration. * Create a DSN string from a configuration.
* *
......
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