Symfony 4 Dotenv escape special characters

Viewed 7316

I use a password with a special char and symfony return an error "Malformed parameter "url"."

How can i use this kind of password ? foo?bar

I try with variables like that

DATABASE_USER='foo'
DATABASE_PASSWORD='foo?bar'
DATABASE_URL=mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@100.100.100.100:3306/db

But is not working

2 Answers

as the variable name suggests, the DATABASE_URL has to be a URL. that is, everything that is a character with meaning in URLs (for example #, ?, :, ...) has to be URL-encoded.

For example ? has to be encoded as %3F if it is supposed to appear in a different meaning than to mark the query. There are lots of tools online to URL-encode stuff...

Use password urlencoded through urlencode() or online:

(e.g: ZZ?*?daWm => ZZ%3F%2A%3FdaWm

Full database url param should like:

DATABASE_URL=mysql://test_user:ZZ%3F%2A%3FdaWm@127.0.0.1:3306/test_db

And then go to ./app/config/packages/doctrine.yaml

I had url parameter with resolve prefix:

doctrine:
    dbal:
        # (....)
        url: '%env(resolve:DATABASE_URL)%'

Simply remove the prefix 'resolve' which fixed the problem, After changes:

doctrine:
    dbal:
        # (....)
        url: '%env(DATABASE_URL)%'
Related