我正在尝试按照电子商务教程,我必须创建与数据库的连接。我在Windows 7上使用xampp v3.2。
所以我用这个:php bin / console generate:doctrine:entity 这给了我这个错误:
SQLSTATE [HY000] [2002]因为目标无法建立连接 机器主动拒绝了它
我关闭了xampp,但我仍然遇到了同样的错误。所以我理解它来自配置;不知怎的,我的shell没有从xampp与我的sql server通信。
这是我的parameters.yml:
# This file is auto-generated during the composer install
parameters:
database_host: localhost
database_port: 3306
database_name: market
database_user: sebastian
database_password:
mailer_transport: smtp
mailer_host: localhost
mailer_user: null
mailer_password: null
secret:
这里是我的config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "@EcommerceBundle/Resources/config/services.yml" }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
我检查了扩展名php_pdo_mysql.dl并启用了它。
我验证了数据库名称,用户和密码。
这是一个netstat: netstat
答案 0 :(得分:0)
确保您的MySQL服务器正在运行并且正在使用该端口(在xampp \ mysql \ bin \ my.ini中)。确保您也可以手动连接这些凭据。
另外,您在parameters.yml中指定数据库驱动程序在哪里?通常你应该有这样的东西:
database_driver: pdo_mysql
最后,请确保您的config_dev.yml中没有包含不同的parameters.yml文件,因为Symfony命令默认使用开发环境。
答案 1 :(得分:0)
谢谢你的回答。 我有my.ini 3306端口所以它是好的。我已经安装了symfony2.8并且它正在工作,所以没有凭据问题。我也尝试用pdo_mysql添加行,但错误消息是pdo_exception,这意味着pdo也可以。 我也检查了config.dev,但我真的不知道里面有什么问题。所以我告诉你它的样子:
imports:
- { resource: config.yml }
framework:
router:
resource: "%kernel.root_dir%/config/routing_dev.yml"
strict_requirements: true
profiler: { only_exceptions: false }
web_profiler:
toolbar: true
intercept_redirects: false
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: [!event]
console:
type: console
channels: [!event, !doctrine]
# uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server configuration
#firephp:
# type: firephp
# level: info
#chromephp:
# type: chromephp
# level: info
#swiftmailer:
# delivery_address: me@example.com
感谢您的帮助
答案 2 :(得分:0)
我无法在xamppp上连接到mysql
在3307端口上的系统上安装mysql 8
及其与laravel的配合很好。
如果需要,请安装mysql工作台(而不是phpmyadmin)