Skip to content

Support for DATABASE_URL  #179

@gebi84

Description

@gebi84

first thx for the great tool.

I'm using the latest version 1.9.0

When i only set the URL in the .env:
DATABASE_URL=mysql://root:root@127.0.0.1/fwgshopmanager_test

I get following error:
[ErrorException] Notice: Undefined index: master

the params array which comes into ConnectionFactory::createConnection looks like so
array:9 [ "url" => "mysql://root:root@127.0.0.1/fwgshopmanager_test" "charset" => "UTF8" "host" => "localhost" "port" => null "user" => "root" "password" => null "driver" => "pdo_mysql" "driverOptions" => [] "defaultTableOptions" => [] ]

My suggestion to fix this would be:

if (isset($params['url']) && !isset($params['dbname'])) {
    $connection = DriverManager::getConnection($params, $config, $eventManager);
    $params = $connection->getParams();
    unset($params['url']);
}

if (isset($params['dbname'])) {
    $dbName = $this->getDbNameFromEnv($params['dbname']);
} else {
    $dbName = $this->getDbNameFromEnv($params['master']['dbname']);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions