The key is ManagerRegistry Class. You can read the method inside.
For example. Maybe you can copy the following code to your IDE directly.
IN ADDITION, you must config multiply database info at the configuration file.
How to config
<?php
namespace SessionBundle\Factory;
use Doctrine\DBAL\Connection;
use Symfony\Bridge\Doctrine\ManagerRegistry;
class DbalFactory
{
/**
* DB name
* @var String
*/
const DEFAULT = 'cAuth';
/**
* @var Connection
*/
private $connection;
/**
* DbalFactory constructor
* @param ManagerRegistry $managerRegistry
*/
public function __construct(ManagerRegistry $managerRegistry)
{
$this->connection = $managerRegistry->getConnection(self::DEFAULT);
}
/**
* get DBconnection
* @return Connection
*/
public function get(): Connection
{
return $this->connection;
}
}
网友评论