I need to run a raw SQL query on a non default connection.
The only way I've seen in the docs to use an alternate connection is to inject ManagerRegistry
. This lets me get an ObjectManager
but I'm not seeing how to execute raw sql.
EntityManager
has the getConnection
method which would let me run raw SQL, but I don't see how to get an entity manager for the alternate connection with DI.
Here's where I'm at based on the documentation to use multiple connections:
public function Foo(ManagerRegistry $doctrine)
{
$om = $doctrine->getManager('foo');
// How do I use $om to create a raw SQL query
}
For reference, here is how symfonycasts shows to do it with an EntityManager, but I'm not sure how to select the foo
connection as injecting will give me the default connection.
$conn = $entityManager->getConnection();
$stmt = $conn->prepare($sql);
$res = $stmt->executeQuery();