我正在部署我的 symfony2 项目,但与远程 mysql 服务器的数据库连接出现问题。似乎 symfony 仍在尝试连接到本地 mysql 实例(使用套接字而不是 tcp),并且没有考虑到正确设置所在的 parameteres.yml。
参数.yml
parameters:
database_driver: pdo_mysql
database_host: subdomain-example.dotcloud.net
database_port: 44569
database_name: db_platform
database_user: root
database_password: [intentionally hidden]
配置.yml
imports:
- { resource: parameters.yml }
doctrine:
dbal:
default_connection: default
connections:
default:
driver: %database_driver%
dbname: %database_name%
user: %database_user%
password: %database_password%
host: %database_host%
port: %database_port%
charset: UTF8
错误堆栈跟踪(当我尝试清除缓存时由控制台或 http 浏览器显示)
PDOException: SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
in /var/www/Symfony/app/cache/dev/appDevDebugProjectContainer.php line 2336
at PDO->__construct('mysql:dbname=db_platform', 'root', '****') in /var/www/Symfony/app/cache/dev/appDevDebugProjectContainer.php line 2336
at appDevDebugProjectContainer->getPdoService() in /var/www/Symfony/app/bootstrap.php.cache line 209
at Container->get('pdo') in /var/www/Symfony/app/cache/dev/appDevDebugProjectContainer.php line 3027
at appDevDebugProjectContainer->getSession_Handler_PdoService() in /var/www/Symfony/app/bootstrap.php.cache line 209
at Container->get('session.handler.pdo') in /var/www/Symfony/app/cache/dev/appDevDebugProjectContainer.php line 3053
at appDevDebugProjectContainer->getSession_Storage_NativeService() in /var/www/Symfony/app/bootstrap.php.cache line 209
at Container->get('session.storage.native') in /var/www/Symfony/app/cache/dev/appDevDebugProjectContainer.php line 3014
at appDevDebugProjectContainer->getSessionService() in /var/www/Symfony/app/bootstrap.php.cache line 209
at Container->get('session') in /var/www/Symfony/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php line 52
........
正如您在上面看到的,配置文件中没有“localhost”,并且在错误堆栈跟踪中,构造方法没有将主机和端口数据传递给 PDO 类:
PDO->__construct('mysql:dbname=db_platform', 'root', '****')
我已经手动删除了缓存文件夹。
作曲家.json
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.1.0",
"doctrine/orm": ">=2.3.0,<2.4.*-dev",
"doctrine/doctrine-bundle": ">=2.1",
"doctrine/mongodb": "1.0.1",
"doctrine/mongodb-odm-bundle": "3.0.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.1.*",
"symfony/swiftmailer-bundle": "2.1.*",
"symfony/monolog-bundle": "2.1.*",
"sensio/distribution-bundle": "2.1.*",
"sensio/framework-extra-bundle": "2.1.*",
"sensio/generator-bundle": "2.1.*",
.... more
},
有什么建议吗?
提前致谢, 毛罗