带有教义的symfony2无法连接到远程mysql数据库 [英] symfony2 with doctrine cannot connect to remote mysql database

查看:41
本文介绍了带有教义的symfony2无法连接到远程mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在部署我的 symfony2 项目,但我遇到了与远程 mysql 服务器的数据库连接问题.似乎 symfony 仍在尝试连接到本地 mysql 实例(使用套接字而不是 tcp),并且没有考虑到正确设置所在的 parameteres.yml.

I'm deploying my symfony2 project and I'm having problems with the database connection to a remote mysql server. It seems like symfony was still trying to connect to a local mysql instance (using socket instead of tcp) and not taking into account the parameteres.yml where are the correct settings.

parameters.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]

config.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 浏览器显示)

Error stack trace (shown by the console when I try to clear cache or by the http browser)

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 类:

As you can see above there is no "localhost" in the config file and in the error stack trace the construct method is not passing the host and port data to the PDO class:

PDO->__construct('mysql:dbname=db_platform', 'root', '****')

我已经手动删除了缓存文件夹.

I have already deleted the cache folder manually.

composer.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
},

有什么建议吗?

提前致谢,毛罗

推荐答案

我可以找出问题所在,是 config.yml 中的 PDO 服务参数:

I could figure out the problem, it was the PDO service arguments in config.yml:

services:
    pdo:
        class: PDO
        arguments:
            - "mysql:host=%database_host%;port=%database_port%;dbname=%database_name%"
            - %database_user%
            - %database_password%

我必须添加主机和端口参数.

I had to add the host and port parameters.

感谢您的回复.
毛罗

Thanks for the replies.
Mauro

这篇关于带有教义的symfony2无法连接到远程mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆