How to solve this SQLSTATE[HY000] [2002] no connection could be made because the target machine actively refused it - database

I am trying to follow an e-commerce tutorial where I have to create the connection with the database. I am on windows 7 with xampp v3.2.
So I use this : php bin/console generate:doctrine:entity
which gives me this error :
SQLSTATE[HY000] [2002] no connection could be made because the target
machine actively refused it
I closed xampp and I still had the same error. So I understand it comes from the configuration; somehow my shell doesn't communicate with my sql server from xampp.
here is my 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:
and here my 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 }
I checked for the extension php_pdo_mysql.dl and it is enabled.
I verified the database name, user and password.
here is a netstat :
netstat

Make sure that your MySQL server is running and that it's using that port (in xampp\mysql\bin\my.ini). Make sure that you're able to connect manually with those credentials as well.
Also, where are you specifying the database driver in your parameters.yml? Normally you should have something like this:
database_driver: pdo_mysql
And lastly, make sure that you don't have a different parameters.yml file included in your config_dev.yml because Symfony commands, by default, use the dev environment.

thank you for your answer.
I have in my.ini 3306 port so it is the good one. I have intalled symfony2.8 and it is working so there is no credentials problems. I also tried to add the line with pdo_mysql but the error message is an pdo_exception, that means pdo works as well.
I also check config.dev but I don't really know what can be wrong inside. So I show you what it looks like :
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
thank for your help

i cant connect to mysql on xamppp
install mysql 8 on my system on port 3307
and its worked great with laravel.
if you want please install mysql workbench (instead of phpmyadmin)

Related

How can I connect SQL Server with ORM Doctrine on my symfony project?

doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
host: 127.0.0.1
port: 8889
user: '%env(DATABASE_USER)%'
password: '%env(DATABASE_PWD)%'
dbname: '%env(DATABASE_NAME)%'
# With Symfony 3.3, remove the `resolve:` prefix
# url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: yml
dir: '%kernel.project_dir%/config/doctrine'
prefix: 'App\Entity'
alias: App
You need to use driver pdo_sqlsrv or sqlsrv, not pdo_mysql.
(See doctrine configuration documentation).
pdo_sqlsrv: A Microsoft SQL Server driver that uses pdo_sqlsrv PDO
sqlsrv: A Microsoft SQL Server driver that uses the sqlsrv PHP
extension.
Available configuration for pdo_sqlsrv/sqlsrv are:
user (string): Username to use when connecting to the database.
password (string): Password to use when connecting to the database.
host (string): Hostname of the database to connect to.
port (integer): Port of the database to connect to.
dbname (string): Name of the database/schema to connect to.
The documentation says that:
The following drivers support automatic database platform detection
out of the box without any extra configuration required:
pdo_mysql
mysqli
pdo_pgsql
pdo_sqlsrv
sqlsrv
So you dont need to specify server_version.
You would have:
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_sqlsrv'
charset: utf8mb4
host: 127.0.0.1
port: 8889
user: '%env(DATABASE_USER)%'
password: '%env(DATABASE_PWD)%'
dbname: '%env(DATABASE_NAME)%'
# With Symfony 3.3, remove the `resolve:` prefix
# url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: yml
dir: '%kernel.project_dir%/config/doctrine'
prefix: 'App\Entity'
alias: App

Symfony Define the database for authentication

I work on a project with Symfony2 and for now i can authenticate on my website.
But my problem is now when a user want to authenticate, i want to use a another database for some reasons.
So how can i say to symfony to use for example the db2 for authenticate and the db1 for the website?
If anyone can help me, thanks!
EDIT:
Thank's for your answer, i write this:
orm:
auto_generate_proxy_classes: %kernel.debug%
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
ContactBundle: ~
users:
connection: general
mappings:
UsersBundle: ~
But i've this error:
The class 'SymagContact\Bundle\UsersBundle\Entity\Users' was not found in the chain configured namespaces SymagContact\Bundle\SymagContactBundle\Entity
Sure you can have more than one EntityManager:
You have to setup your DBAL connections like this:
# Doctrine Configuration
doctrine:
dbal:
default_connection: default
connections:
default:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
db2:
driver: "%db2_database_driver%"
host: "%db2_database_host%"
port: "%db2_database_port%"
dbname: "%db2_database_name%"
user: "%db2_database_user%"
password: "%db2_database_password%"
Then in the ORM section you can map your UserBundle namespace to the db2 connection:
doctrine:
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
AppBundle: ~
AcmeStoreBundle: ~
customer:
connection: db
mappings:
AcmeUserBundle: ~
The rest is just the same: Have a UserProvider registered that follows the UserProviderInterface.
See http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html for more information.

Error setting multiple db symfony 2.5

i'm trying to set 2 databases to my symfony 2.5 project, but got this error:
Fatal error: Uncaught exception 'Symfony\Component\DependencyInjection\Exception\InvalidArgumentException' with message 'The service definition "doctrine.dbal.default_connection" does not exist.' \services\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\ReplaceAliasByActualDefinitionPass.php on line 48
Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: The service definition "doctrine.dbal.default_connection" does not exist. in services\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ContainerBuilder.php on line 867
Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: Unable to replace alias "doctrine.dbal.default_connection" with "database_connection"
Here is my doctrine definition config.yml
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: localhost
port: ~
name: db1
user: root
password: ~
log:
driver: pdo_mysql
host: localhost
port: ~
name: db2
user: root
password: ~
Any suggestion?
The error message Unable to replace aliaswhen fidling with multiple databases hints to a typo in your configuration.
Double check your configuration using this reference: http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html

Connection refused - connect(2) rails

I copied a source code from github, and then I install ruby,rails,mysql...,which are necessary!
this is the config/database.yml :
common: &common
adapter: mysql2
encoding: utf8
reconnect: true
# socket: /var/run/mysqld/mysqld.sock
common settings for any development databases
devel_common: &dev
host: localhost
username: root
password: wjn_123
common settings for all test databases
tst_common: &tst
host: localhost
username: root
password: wjn_123
common settings for all integration databases
int_common: &remote
host: localhost
username: root
password: wjn_123
.......
then I execute "rake eol:db:recreate RAILS_ENV=development" and there is no exception.but when I execute "rake eol:db:populate" and it gives me this :
Rebuilding BHL ...
Error accessing http:// localhost :8983/solr/bhl/update
"Connection refused - connect(2)"
.....
rake aborted!
Connection refused - connect(2)
/usr/local/rvm/gems/ruby-1.9.3-p392#upgrade/gems/webmock-1.8.11/lib/webmock/http_lib_adapters/net_http.rb:98:in request'
/usr/local/rvm/gems/ruby-1.9.3-p392#upgrade/gems/webmock-1.8.11/lib/webmock/http_lib_adapters/net_http.rb:116:instart_without_connect'
/usr/local/rvm/gems/ruby-1.9.3-p392#upgrade/gems/webmock-1.8.11/lib/webmock/http_lib_adapters/net_http.rb:131:in `start'
so how can I solve the problem .
and I did not install jdk/jre . is that the reason?
Do you think it might have anything to do with the issue mentioned by Houen in http://railscasts.com/episodes/278-search-with-sunspot?view=comments ?

Symfony 2 FOSUserBundle with different db connection than other bundles

I want to build a site where users can log in register and that stuff. For the User management i use FOSUserbundle. Now i want to use a different db connection for FOSUserBundle than for the other bundles. My config.yml file looks like:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: "%database1_driver%"
host: "%database1_host%"
port: "%database1_port%"
dbname: "§database1_name%"
user: "%database1_user%"
password: "%database1_password%"
charset: UTF8
user:
driver: "%database2_driver%"
host: "%database2_host%"
port: "%database2_port%"
dbname: "%database2_name%"
user: "%database2_user%"
password: "%database2_password%"
charset: UTF8
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
MyProjectMainBundle: ~
user:
connection: user
mappings:
MyProjectUserBundle: ~
When i try to load the page i get the error MappingException: The class 'MyProject\UserBundle\Entity\User' was not found in the chain configured namespaces MyProject\MainBundle\Entity, FOS\UserBundle\Model.
I followed the documentation for FOSUserBundle exactly and it is working if i use
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
in config.yml.
The only thing with this is, it only generates the table like defined in the new entity from the documentation. Only an id field is generated, and not the whole fos_user table like it should.
I know some similar questions have been asked before, but I tried using all the solutions from there and it didn't work. So how can I fix this? Is it even possible? I really need to use seperate databases because my project will use a lot of tables and i don't want it to get too messy.
user:
connection: user
mappings:
FOSUserBundle: ~
MyProjectUserBundle: ~
Need to add the FOSUserBundle to your mappings to get rid of the entity error
And make sure you have the model_manager_name set in config.ym;
fos_user:
db_driver: orm
firewall_name: main
user_class: Cerad\Bundle\AccountBundle\Entity\AccountUser
model_manager_name: user

Resources