Lay*_*son 5 php mysqlconnection doctrine-orm symfony4
我很难让数据库连接与Symfony4 w / doctrine2中使用的mysql url格式一起使用。
这是我想要做的:
mysql://dbusername:dbpassword@unix_socket(/path/to/socket)/dbname
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?请指教。Doctrine2文档尚不清楚通过套接字进行连接的格式。
在尝试将Google Cloud Platform SQL用于需要使用本地unix套接字的mysql时,我也遇到了此问题。
URL的每个部分都不是必需的,其形式为:
<type>://[user[:password]@][host][:port][/db][?param_1=value_1¶m_2=value_2...]
Run Code Online (Sandbox Code Playgroud)
因此,对于mysql unix套接字,如果需要指定用户名和密码,则可以执行以下操作:
mysql://user:password@127.0.0.1/db_name/?unix_socket=/path/to/socket
Run Code Online (Sandbox Code Playgroud)
127.0.0.1部分将被忽略。
您可以通过以下parse_url功能测试该功能是否在起作用(该功能在内部由教义使用):
php > var_dump(parse_url("mysql://user:password@127.0.0.1/db_name/?unix_socket=/path/to/socket"));
php shell code:1:
array(6) {
'scheme' =>
string(5) "mysql"
'host' =>
string(9) "127.0.0.1"
'user' =>
string(4) "user"
'pass' =>
string(8) "password"
'path' =>
string(9) "/db_name/"
'query' =>
string(27) "unix_socket=/path/to/socket"
}
Run Code Online (Sandbox Code Playgroud)