12

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

n44s
  • 443
  • 4
  • 18

2 Answers2

14

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...

Jakumi
  • 8,043
  • 2
  • 15
  • 32
10

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)%'
Anil Gupta
  • 1,593
  • 1
  • 19
  • 21
  • It appears that the Symfony resolve function will try to replace %foo% with a variable defined in the YAML. That's why it fails in our case. See https://symfony.com/doc/current/configuration/env_var_processors.html#built-in-environment-variable-processors – Stefan Rickli Jul 06 '23 at 14:25