KhorneHoly
KhorneHoly

Reputation: 4766

Symfony2/Doctrine2 - Escaping special char in password

How can I escape a password I'm using for a database connection via Doctrine?

In my password is an "@" and Symfony2 will give me this error:

SQLSTATE[28000] [1045] Access denied for user 'user'@'server' (using password: YES)

The password is correct, it works everywhere but my Symfony2 project

Upvotes: 3

Views: 1467

Answers (1)

Falc
Falc

Reputation: 595

Strings containing non-alphanumeric characters can be escaped using single or double quotes:

parameters:
    database_password: "my:pass@word!"

If you want to use a string that starts with "@" you must escape it prepending another "@", as stated in The Book - Service Container.

So, if your password is "@mypassword":

parameters:
    password1: "@mypassword"  # Will not work
    password2: "@@mypassword" # Will work

This is required because strings starting with a single "@" are used as service identifiers.

Upvotes: 1

Related Questions