Answer the question
In order to leave comments, you need to log in
How to describe entities for another base?
Hello everyone, in short, I need to create dynamic connections in the database, the connection itself turned out to be done, but I still don’t really understand how to deal with entities and repositories.
Create a dynamic connection to the database
$params['user'] = 'qwerty';
$params['host'] = 'localhost';
$params['port'] = 3306;
$params['dbname'] = 'test';
$params['password'] = 'test';
$params['url'] = 'mysql://qwerty:[email protected]:3306/test';
$connection = EntityManager::create(
$params,
$this->em->getConfiguration(),
$this->em->getEventManager()
);
src/Entity/Test/MyTable
$connection->getRepository(MyTable::class)->findAll();
/**
* @ORM\Entity(repositoryClass="App\Repository\Test\MyTableRepository")
* @ORM\Table(name="my_table")
*/
Answer the question
In order to leave comments, you need to log in
Symfony has documentation on this topic: https://symfony.com/doc/current/doctrine/multiple_... And you can see an
example from real life, for example, in my mini-project. There PostgreSQL and SQLite work at the same time.
Attention should be paid to . This, of course, is for previously known compounds.
Well, for entities from each database, use your own EntityManager. This is in any case - regardless of whether the connections are defined in advance or at runtime.
Most likely, you are using the wrong EntityManager or creating it with the wrong connection.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question