gpt4 book ai didi

mysql - 具有 Doctrine 的symfony2无法连接到远程mysql数据库

转载 作者:行者123 更新时间:2023-11-29 01:22:36 26 4
gpt4 key购买 nike

我正在部署我的 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]

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

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', '****')

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

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 服务参数:

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

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

感谢您的回复。
毛罗

关于mysql - 具有 Doctrine 的symfony2无法连接到远程mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14288776/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com