M
M
Maxim Lagoysky2019-04-19 11:28:45
symfony
Maxim Lagoysky, 2019-04-19 11:28:45

Why is it not getting data from another database?

I decided to try to use several databases, looked at the docks, took the config from there, but something doesn’t work.

Here is the config
doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                # configure these for your database server
                url: '%env(DATABASE_URL)%'
                driver: 'pdo_mysql'
                server_version: '5.7'
                charset: utf8mb4
            customer:
                # configure these for your database server
                url: '%env(DATABASE_CUSTOMER_URL)%'
                driver: 'pdo_mysql'
                server_version: '5.7'
                charset: utf8mb4

    orm:
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                mappings:
                    Main:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity'
                        prefix: 'App\Entity'
                        alias: Main
            customer:
                connection: customer
                mappings:
                    Customer:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity'
                        prefix: 'App\Entity'
                        alias: Customer


In each of the databases, I created a User table and filled in different data.
But with such a selection, I still get data from the default connection. What have I done wrong?
$this->getDoctrine()->getRepository(User::class, 'customer')->findAll();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Lagoysky, 2019-05-31
@lagoy

In short, an error in namespaces, I had the same ones, I made different namespaces right away, everything became normal.

D
Denis Derepko, 2019-04-19
@uDenX

Reading the documentation: https://symfony.com/doc/current/doctrine/multiple_...

$entityManager = $this->getDoctrine()->getManager('default');
$customerEntityManager = $this->getDoctrine()->getManager('customer');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question