Skip to content

Standalone DSN parser #5814

@derrabus

Description

@derrabus

Feature Request

Q A
New Feature yes
RFC no

Summary

In #5697, we have deprecated driver aliases for database URLs. One use-case of those aliases was to be able to parse a credentials URL like mysql://my_user:my_password@my.database-host.local that are usually provided by a PaaS services. With the changes on 4.0, those database URLs would become specific to Doctrine because we would have to use mysqli:// or pdo-mysql:// as scheme.

My idea would be to deprecate the url option completely and replace it with a standalone DSN parser that translates a given DSN into an array of options that can be passed to DriverManager. This parser can be configured with a scheme-to-driver mapping (e.g. ['mysql' => 'pdo_mysql']).

I see several advantages of this approach:

  • The DBAL does not decide which driver to pick for a database engine, if multiple drivers exist.
  • The array can be modified before it's passed to DriverManager.
    • Adding settings that the DSN does not cover is simple and discoverable.
    • It is easier to see how settings from the DSN can be overridden.
  • The array can be cached by the application which means we don't need to parse the DSN on each request.
  • DriverManager's internal logic gets a little bit simpler.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions