I
I
Irina2015-02-05 09:48:28
symfony
Irina, 2015-02-05 09:48:28

How to refer to the second connection in Symfony 2?

Good morning!
There is a question.
I ran into a problem while building the query.
There are two databases, database_one, database_two.
In the yml configuration, I wrote two connections base (database_one) and bigdata (database_two).
Naturally base goes by default.
I can’t figure out / find in the documentation how to use the second connection.
To be more precise, I have no idea how to access bigdata using getRepository
Example

// Так мы обратимся к второй БД.
$this->get('doctrine') ->getRepository('MyBundle:MyEntity', 'bigdata')->findAll();

But I can't figure out how to use createQueryBuilder and createQuery constructs to write DQL.
You can point to the documentation or an example.
I would appreciate that.
Thanks ;)
They say it seems like Sergei Protko can tell =)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-02-05
@IrishkaDeutsch

You can use the following:

// Указываем к какому параметру соединения обращаться.
$em   = $this->getDoctrine()->getManager('bigdata');
// Выполняем
$query = $em->createQuery(" SELECT p FROM MyBundle:CountryCore p ");
....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question