Skip to content

Commit 5900cec

Browse files
authored
Added support for selecting the database (#354)
Now the connection supports the 'database' configuration parameter as well
1 parent 66b0276 commit 5900cec

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Connection.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,16 @@ public function getPort(array $config)
450450
return Arr::get($config, 'port', $this->defaults['port']);
451451
}
452452

453+
/**
454+
* Get the database name.
455+
*
456+
* @return null|string
457+
*/
458+
public function getDatabase(array $config)
459+
{
460+
return Arr::get($config, 'database', null);
461+
}
462+
453463
/**
454464
* Get the connection username.
455465
*
@@ -1210,6 +1220,11 @@ private function buildUriFromConfig(array $config): string
12101220
$uri .= ':' . $port;
12111221
}
12121222

1223+
$database = $this->getDatabase($config);
1224+
if ($database) {
1225+
$uri .= '?database='.urlencode($database);
1226+
}
1227+
12131228
return $uri;
12141229
}
12151230

0 commit comments

Comments
 (0)