symfony 连接mysql报错,symfony2与doctrine无法连接到远程mysql数据库

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

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

........

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

},

Any suggestion?

Thanks in advance,

Mauro

解决方案

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值