简体   繁体   English

symfony2数据库主机是localhost

[英]symfony2 database host is localhost

Here is my parameters.yml 这是我的parameters.yml

parameters:
    database_driver: pdo_mysql
    database_host: 192.168.1.7
    database_port: null
    database_name: kpb
    database_user: kpb_user

here is echo $this->container->getParameter('database_host') - from controller 这是echo $this->container->getParameter('database_host') -来自控制器

192.168.1.7

here is stack trace - 这是堆栈跟踪-

2. at PDO ->__construct ('mysql:host=localhost;dbname=kpb;charset=UTF8;', 'kochampo_user', '

here is ... 这是 ...

echo __FILE__;
        var_dump($params);
        die();


vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.phparray(8) { ["driver"]=> string(9) "pdo_mysql" ["dbname"]=> string(3) "kpb" ["user"]=> string(8) "kpb_user" ["password"]=> string(12) "****" ["charset"]=> string(4) "UTF8" ["host"]=> string(9) "localhost" ["port"]=> NULL ["driverOptions"]=> array(0) { } } 



grep -r "localhost" app/config/ 

return null 

cache is cleare by cache:clear and i delete cache directory manually (database name change immediately) . cache由cache:clear ,我手动删除缓存目录(数据库名称立即更改)。

so how to change database host? 那么如何更改数据库主机? why always is localhost ? 为什么总是localhost

You need to have next strings in your config.yml to make your db connection use host from parameters bag: 您需要在config.yml包含下一个字符串,以使您的数据库连接使用参数包中的主机:

doctrine:
    dbal:
        host:     "%database_host%"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM