From 5900cec86c59fdf6db3fe5839d9ed166d697dbec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nagy=20Attila=20G=C3=A1bor?= Date: Mon, 7 Mar 2022 16:04:53 +0100 Subject: [PATCH] Added support for selecting the database (#354) Now the connection supports the 'database' configuration parameter as well --- src/Connection.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Connection.php b/src/Connection.php index a27dd704..33629832 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -450,6 +450,16 @@ public function getPort(array $config) return Arr::get($config, 'port', $this->defaults['port']); } + /** + * Get the database name. + * + * @return null|string + */ + public function getDatabase(array $config) + { + return Arr::get($config, 'database', null); + } + /** * Get the connection username. * @@ -1210,6 +1220,11 @@ private function buildUriFromConfig(array $config): string $uri .= ':' . $port; } + $database = $this->getDatabase($config); + if ($database) { + $uri .= '?database='.urlencode($database); + } + return $uri; }