Gets the database connection object used by the EntityManager.
public getConnection ( ) : Doctrine\DBAL\Connection | ||
return | Doctrine\DBAL\Connection |
use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; // create a connection $connection = DriverManager::getConnection([ 'dbname' => 'test', 'user' => 'root', 'password' => '', 'host' => 'localhost', 'driver' => 'pdo_mysql' ]); // create an entity manager $entityManager = EntityManager::create($connection); // get the connection $conn = $entityManager->getConnection();
use Doctrine\ORM\EntityManager; // create an entity manager $entityManager = EntityManager::create([ 'url' => 'mysql://username:password@localhost/test', 'driver' => 'pdo_mysql' ]); // get the connection $conn = $entityManager->getConnection();In this example, we create an entity manager directly from the database URL. We then use the `getConnection()` method to get the connection instance. In summary, the `EntityManager getConnection` method is used to retrieve the connection instance for a database from an entity manager. It belongs to the php doctrine.orm package library.
public getConnection ( ) : Doctrine\DBAL\Connection | ||
return | Doctrine\DBAL\Connection |