Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 条令2.0,连接到多个数据库_Php_Pdo_Doctrine Orm_Sql Server 2008 R2 - Fatal编程技术网

Php 条令2.0,连接到多个数据库

Php 条令2.0,连接到多个数据库,php,pdo,doctrine-orm,sql-server-2008-r2,Php,Pdo,Doctrine Orm,Sql Server 2008 R2,我在一个项目上遇到了一些麻烦 我目前正在尝试将Doctrine 2.0用于一个PHP项目。 仅供参考,我没有安装symphony或zend 服务器是MSSQLServer2008R2,我使用的是php_pdo_sqlsrv驱动程序 我的问题与连接的配置有关 事实上,我必须只配置到服务器主机的连接,并且只在Entities类中集成数据库名称 在我的测试中,我使用了以下代码来连接、实例化我的EntityManager并获取我的实体: // the connection configuration $

我在一个项目上遇到了一些麻烦

我目前正在尝试将Doctrine 2.0用于一个PHP项目。
仅供参考,我没有安装symphony或zend

服务器是MSSQLServer2008R2,我使用的是php_pdo_sqlsrv驱动程序

我的问题与连接的配置有关

事实上,我必须只配置到服务器主机的连接,并且只在Entities类中集成数据库名称

在我的测试中,我使用了以下代码来连接、实例化我的EntityManager并获取我的实体:

// the connection configuration
$dbParams = array(
    'driver'   => 'pdo_sqlsrv',
    'user'     => 'my_user',
    'password' => 'my_pass',
    'dbname'   => 'dbtest',
    'host' => 'hostname'
);

$config = Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration($paths,     $isDevMode);
$em = EntityManager::create($dbParams, $config);


$entity = $em->find('myEntity', 1);
echo $entity->getLibelle();
下面是我的班级

/**
 * @Entity
 * @Table(name="tableEntity")
 */
class Entity
{
    /** @Id @Column(type="integer") @GeneratedValue */
    private $ID_ENTITY;

    /**
     * @Column(type="string")
     */
    private $LIBELLE;

    public function __construct($name)
    {
        $this->LIBELLE = $LIBELLE;        
    }

    public function getID_ENTITY()
    {
        return $this->ID_ENTITY;
    }

    public function getLibelle()
    {
        return $this->LIBELLE;
    }
}
使用此配置,我不会遇到任何问题,我的“诽谤”也不会出现问题。
但是我想做的(也许是一个梦?)不是配置dbname,比如:

// the connection configuration without dbname
$dbParams = array(
    'driver'   => 'pdo_sqlsrv',
    'user'     => 'my_user',
    'password' => 'my_pass',
    'host' => 'hostname'
);
并将dbname集成到实体中,例如:

/**
* @Entity
* @Table(name="DBNAME.tableEntity")
*/
有什么问题吗? 非常感谢你的帮助