PHP code example of ngabor84 / laravel-dbconnstring-parser

1. Go to this page and download the library: Download ngabor84/laravel-dbconnstring-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ngabor84 / laravel-dbconnstring-parser example snippets


'providers' => [
    ...
    \Service\Database\ConnectionStringParser\Providers\ServiceProvider::class,
]

$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
            )
        ]
    ]
];

// uncomment this line to enable Facades
$app->withFacades();
...
$app->register(\Service\Database\ConnectionStringParser\Providers\ServiceProvider::class);

$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
            )
        ]
    ]
];