Doctrine/Symfony MariaDB DSN connection string

When connecting to MySQL/MariaDB with Doctrine you need to specify the version number of the server in the serverVersion query string parameter. In the past it was as simple as serverVersion=mariadb-10.5.10 and things just worked. Recent updates to Doctrine’s DBAL have started to throw warnings that version 4 will require a change to this:

Version detection logic for MySQL will change in DBAL 4. Please specify the version as the server reports it, e.g. "10.9.3-MariaDB" instead of "mariadb-10.9"

Unfortunately, that’s not what the documentation says, although in my testing it does work. The documentation says to log into the database and run a SELECT VERSION() query which produces a much uglier version number such as 10.5.22-MariaDB-1:10.5.22+maria~ubu2004.

At the end of the day I don’t care a whole lot, I rarely need to deal with this, but it looks ugly and my web-dev brain hates seeing certain characters in a URL.