美文网首页
How to use multiply database wit

How to use multiply database wit

作者: 王晨玮Mark | 来源:发表于2019-04-16 16:02 被阅读0次

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;
    }
}

相关文章

网友评论

      本文标题:How to use multiply database wit

      本文链接:https://www.haomeiwen.com/subject/buibwqtx.html