Package Data | |
---|---|
Maintainer Username: | ngabor84 |
Maintainer Contact: | negabor@gmail.com (Gabor Nemeth) |
Package Create Date: | 2018-10-25 |
Package Last Update: | 2023-06-09 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-23 03:12:11 |
Package Statistics | |
---|---|
Total Downloads: | 3,128 |
Monthly Downloads: | 33 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Small service to parse database connection string into parts.
This package allows you to parse database connection string into parts.
Require the ngabor84/laravel-dbconnstring-parser package in your composer.json and update your dependencies:
composer require ngabor84/laravel-dbconnstring-parser
Add the service provider to the providers array in the config/app.php config file as follows:
'providers' => [
...
\Service\Database\ConnectionStringParser\Providers\ServiceProvider::class,
]
In your database config file you can use it like this:
$connection = ConnectionStringParser::parse(env('DATABASE_URL'));
return [
'default' => 'pgsql',
'connections' => [
'pgsql' => [
'driver' => 'pgsql',
'host' => $connection->getHost(),
'username' => $connection->getUserName(),
'password' => $connection->getPassword(),
'port' => $connection->getPort(),
'database' => $connection->getDatabase(),
'charset' => 'utf8',
'options' => array(
PDO::ATTR_PERSISTENT => true
)
]
]
];
Add the following snippet to the bootstrap/app.php file under the providers section as follows:
// uncomment this line to enable Facades
$app->withFacades();
...
$app->register(\Service\Database\ConnectionStringParser\Providers\ServiceProvider::class);
In your database config file you can use it like this:
$connection = ConnectionStringParser::parse(env('DATABASE_URL'));
return [
'default' => 'pgsql',
'connections' => [
'pgsql' => [
'driver' => 'pgsql',
'host' => $connection->getHost(),
'username' => $connection->getUserName(),
'password' => $connection->getPassword(),
'port' => $connection->getPort(),
'database' => $connection->getDatabase(),
'charset' => 'utf8',
'options' => array(
PDO::ATTR_PERSISTENT => true
)
]
]
];