Commit 2ceadc0d authored by Kim Hemsø Rasmussen's avatar Kim Hemsø Rasmussen

Added parameter "default_dbname" to pdo_pgsql driver which can be used to...

Added parameter "default_dbname" to pdo_pgsql driver which can be used to override the default database
parent a3a86aa5
......@@ -250,6 +250,8 @@ pdo\_pgsql
- ``dbname`` (string): Name of the database/schema to connect to.
- ``charset`` (string): The charset used when connecting to the
database.
- ``default_dbname`` (string): Override the default database(postgres)
to connect to.
- ``sslmode`` (string): Determines whether or with what priority
a SSL TCP/IP connection will be negotiated with the server.
See the list of available modes:
......
......@@ -88,12 +88,13 @@ class Driver extends AbstractPostgreSQLDriver
if (isset($params['dbname'])) {
$dsn .= 'dbname=' . $params['dbname'] . ' ';
} elseif (isset($params['default_dbname'])) {
$dsn .= 'dbname=' . $params['default_dbname'] . ' ';
} else {
// Used for temporary connections to allow operations like dropping the database currently connected to.
// Connecting without an explicit database does not work, therefore "postgres" database is used
// as it is certainly present in every server setup.
$dsn .= 'dbname=postgres' . ' ';
}
if (isset($params['sslmode'])) {
$dsn .= 'sslmode=' . $params['sslmode'] . ' ';
......
......@@ -2,6 +2,7 @@
namespace Doctrine\Tests\DBAL\Functional\Driver\PDOPgSql;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\PDOPgSql\Driver;
use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest;
......@@ -20,6 +21,26 @@ class DriverTest extends AbstractDriverTest
}
}
public function testDefaultDatabaseOption()
{
$params = $this->_conn->getParams();
$dbName = $params['dbname'];
$params['default_dbname'] = $dbName;
unset($params['dbname']);
$connection = new Connection(
$params,
$this->_conn->getDriver(),
$this->_conn->getConfiguration(),
$this->_conn->getEventManager()
);
$this->assertSame(
$dbName,
$this->driver->getDatabase($connection)
);
}
/**
* @group DBAL-1146
*/
......
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