0

Is there a way to create mongodb connection using doctrine's DriverManager::getConnection() method? Most of examples use yaml file to configure connections. I am looking for a way to make doctrine-mongodb connections only with php code.

2 Answers 2

2

Doctrine\DBAL\DriverManager is not related to the doctrine/mongodb library. DBAL is an analogous to doctrine/mongodb in that they're both database abstraction layers w/o the modeling aspect, but DBAL is specific to SQL drivers (e.g. PDO, DB2).

In DBAL, there are various driver classes, and the manager class merely abstracts their construction. For doctrine/mongodb, there is no need for a manager since MongoDB connections all use the PECL driver's own MongoClient class. Constructing a Doctrine\MongoDB\Connection instance will be sufficient.

0

Looking at the Doctrine ODM Introduction docs, this seems to be the correct way:

<?php
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\MongoDB\Connection;

$connection = new Connection();
$dm = DocumentManager::create($connection, $config);
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.