Skip to content

Commit

Permalink
Added support for selecting the database (#354)
Browse files Browse the repository at this point in the history
Now the connection supports the 'database' configuration parameter as well
  • Loading branch information
mrbig authored Mar 7, 2022
1 parent 66b0276 commit 5900cec
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -1210,6 +1220,11 @@ private function buildUriFromConfig(array $config): string
$uri .= ':' . $port;
}

$database = $this->getDatabase($config);
if ($database) {
$uri .= '?database='.urlencode($database);
}

return $uri;
}

Expand Down

0 comments on commit 5900cec

Please sign in to comment.