B
B
BonBon Slick2017-11-25 12:25:05
PostgreSQL
BonBon Slick, 2017-11-25 12:25:05

Symfony 4 connect to PostgreSQL?

https://symfony.com/doc/master/reference/configura...

#config/config.yml
doctrine:
    dbal:
      charset: utf8mb4
        default_table_options:
          charset: utf8mb4
          collate: utf8mb4_unicode_ci
      default_connection: pgsql
      connections:
         #Postgresql
         pgsql:
              driver:   pdo_pgsql
              host:     "%psql_database_host%"
              port:     "%psql_database_port%"
              dbname:   "%psql_database_name%"
              user:     "%psql_database_user%"
              password: "%psql_database_password%"
              charset:  UTF8

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

#config/parameters.tml
parameters:
    psql_database_driver: pdo_pgsql
    psql_database_host: 127.0.0.1
    psql_database_port: 5432
    psql_database_name: test
    psql_database_user: homestead
    psql_database_password: secret

# .env
###> doctrine/doctrine-bundle ###
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Configure your db driver and server_version in config/packages/doctrine.yaml
#DATABASE_URL=mysql://db_user:[email protected]:3306/db_name
DATABASE_URL=pgsql://homestead:[email protected]:5432/test
#DATABASE_URL=pgsql://localhost:5432/test
###< doctrine/doctrine-bundle ###

Errors:
// php bin/console doctrine:database:create --connection=pgsql

2017-11-25T09:22:43+00:00 [error] Error thrown while running command "doctrine:database:create --connection=pgsql". Message: "Doctrine ORM Connection named "pgsql" does not exist."

In AbstractManagerRegistry.php line 125:

  Doctrine ORM Connection named "pgsql" does not exist.


// php bin/console doctrine:database:create

In PDOConnection.php line 43:

  SQLSTATE[08006] [7] could not connect to server: Connection refused (0x0000274D/10061)
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?
  could not connect to server: Connection refused (0x0000274D/10061)
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?

The database is up and running on Vagrant + Homestead. I can manually control via PhpStorm
None of the above work, why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
padlyuck, 2017-11-25
@BonBonSlick

taken from here https://www.tutodidacte.com/symfony2-utiliser-une-...

# Doctrine Configuration
doctrine:
    orm:
        entity_managers:
            pgsql:
                connection: pgsql    # connection name for your additional DB
                # bundles utilisant la connexion Postgresql
                mappings:
                   # PostgresqlBundle: ~

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question