php - Problem to recover data from several databases in Symfony 5

Solution:

I found the solution. Finally it is an anomaly of Symfony 5. I renamed the entity folder "ErpEntity" (instead of "EntityErp") and it works. Strange, but I can close this post.

Answer

Solution:

The connection starts with your entity manager so you would want to do it this way:

$em1 = $this->getDoctrine()->getManager();
$em2 = $this->getDoctrine()->getManager('erp');

$em1 would be your default first database, $em2 would be the second (erp)

Then construct your query this way:

$totos = $em2->getRepository(Toto::class)->findAll();

Source