Symfony2 / Doctrine2 - 转换密码中的特殊字符 [英] Symfony2/Doctrine2 - Escaping special char in password
问题描述
如何通过Doctrine逃脱我用于数据库连接的密码?
How can I escape a password I'm using for a database connection via Doctrine?
在我的密码是一个@,Symfony2会给我这个错误:
In my password is an "@" and Symfony2 will give me this error:
SQLSTATE [28000] [1045]访问被拒绝用户'user'@'服务器'(使用密码:YES)
密码是正确的,它可以在任何地方使用,但我的Symfony2项目
The password is correct, it works everywhere but my Symfony2 project
推荐答案
可以使用单引号或双引号转义包含非字母数字字符的字符串:
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.
所以,如果你的密码是@mypassword:
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.
这篇关于Symfony2 / Doctrine2 - 转换密码中的特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!