Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException #72

Open
Lazur opened this issue Sep 19, 2017 · 10 comments
Open

Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException #72

Lazur opened this issue Sep 19, 2017 · 10 comments

Comments

@Lazur
Copy link

Lazur commented Sep 19, 2017

Hi, thanks for your work.
I have a problem, which I can't handle by self. All things configured as described in readme. And generally symfony app works, but until I don't try to make a query. Confusing thing is what I can create database, update scheme, but can't perform queries in my app. I checked log files this is the message. I have no idea how to solve it. Could you give any tip about this issue?
Thanks.

Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException: "An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused" at /var/www/symfony/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 103 {"exception":"[object ] (Doctrine\\DBAL\\Exception\\ConnectionException(code: 0): An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused at /var/www/symfony/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:103, Doctrine\\DBAL\\Driver\\PDOException(code: 2002): SQLSTATE[HY000] [2002] Connection refused at /var/www/symfony/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:47, PDOException(code: 2002): SQLSTATE[HY000] [2002] Connection refused at /var/www/symfony/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43)"} []

@maxpou
Copy link
Owner

maxpou commented Sep 19, 2017

Hiya,

Could you tell me a bit more about your problem?

So if you can run command through Symfony and you cannot with whatever PHP service, maybe the service don't use the same Connection Provider. Isn't it?

Regards

@Lazur
Copy link
Author

Lazur commented Sep 20, 2017

I can use creds from env files and enter via pma to database. I can create entity and update schema inside of php container, so mysql works. But symfony app can't connect to database.
In parameters.yml I use the creds from env file. Which info do you need?

@themark147
Copy link

themark147 commented Sep 30, 2017

I have same problem ... mysql works, creating schema works, i can connect to db via SQL client but via web i can't connect. Same error:
"Doctrine\DBAL\Exception\ConnectionException
An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused"

@tomasyhy
Copy link

Make sure that you have changed app/config/parameters.yml as was mentioned in 4. Prepare Symfony app of installation.

@Lazur
Copy link
Author

Lazur commented Oct 29, 2017

Sure I had checked it.
Trying to init database for symfony from php container.

root@33c2370b0890:/var/www/symfony# sf doctrine:database:create
                                                                             
  [Doctrine\DBAL\Exception\ConnectionException]                              
  An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused  
                                                                             
  [Doctrine\DBAL\Driver\PDOException]        
  SQLSTATE[HY000] [2002] Connection refused  
                                                                    
  [PDOException]                             
  SQLSTATE[HY000] [2002] Connection refused

But I still can connect from local machine. This goes on mac.

@oxydedefer
Copy link

Same on Ubuntu:


root@7ce187b671e9:/var/www/symfony# sf3 doctrine:database:create
                                                                      
  [Doctrine\DBAL\Exception\ConnectionException]                              
  An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused  
                                 
  [Doctrine\DBAL\Driver\PDOException]        
  SQLSTATE[HY000] [2002] Connection refused  
                  
  [PDOException]                             
  SQLSTATE[HY000] [2002] Connection refused  :

@alenn-m
Copy link

alenn-m commented Nov 3, 2017

I have the same problem

@salletti
Copy link

salletti commented Feb 5, 2018

I solved problem by replacing localhost (or 127.0.0.1) by "db". You can see my configuration below:

parameters:
    env(DATABASE_URL): 'mysql://root@db:3306/symfony'

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4

        # 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: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

And in docker-compose file:

db:
        image: mysql
        ports:
            - "3306:3306"
        environment:
          MYSQL_ALLOW_EMPTY_PASSWORD: 1
          MYSQL_DATABASE: symfony

@mgm2030
Copy link

mgm2030 commented Mar 29, 2018

Having the same problem. What a nightmare¡
The thing is that i have the configuration as below since the beginning and still not working

parameters:
database_host: db
database_port:
database_name: agency
database_user: root
database_password: pass
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: ThisTokenIsNotSoSecretChangeIt

this is my docker-compose

version: '3.1'

services:
server:
container_name: api_server
build:
context: .
dockerfile: php7.Dockerfile
image: api_server
restart: always
ports:
- '5015:80'
volumes:
# - api:/var/www/html
- ./server/:/var/www/html
# - ./www-data:/var/www/html
client:
container_name: api_client
build:
context: .
dockerfile: php7.Dockerfile
image: api_client
restart: always
ports:
- '5020:80'
volumes:
- ./client/:/var/www/html

db:
container_name: db
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: pass
MYSQL_DATABASE: agency
volumes:
- mysql-data:/var/lib/mysql
ports:
- '5500:3306'

Any idea?

@PyRowMan
Copy link

parameters:
    database_host: db
    database_port: 5500
    database_name: agency
    database_user: root
    database_password: pass
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    secret: ThisTokenIsNotSoSecretChangeIt

@mgm2030 this should work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants