2017-10-13 8 views
0

私はこの記事と非常に似た何かをしようとしています - Dynamic database connection symfony2 - でもSilexです。Doctrine 2とのSilexでの動的データベース接続

ベースデータベースと、動的に接続したいデータベースを正常にセットアップしました。

database: 
    base: 
    driver: pdo_sqlite 
    path: database/dev.sqlite 
    website: 
    driver: pdo_sqlite 
    path: ~ 

上記$dbs_optionsに読み込まれた後、次はこれを設定するために使用されています。私は成功したウェブサイトのデータベースの名前を取得するにはbasedbを尋問することができる午前私のbeforeイベントで

$app -> register(new DoctrineServiceProvider, ['dbs.options' => $dbs_options]); 

    // configure the ORM identities 
    $app -> register(new DoctrineOrmServiceProvider, [ 
      'orm.proxies_dir' => Utils::joinPaths($app -> config -> appRoot, 'running', 'proxies'), 
      'orm.em.options' => [ 
       'mappings' => $mappings 
      ] 
     ] 
    ); 

    // set up multiple entity managers and assign the base connection as default 
    $app['orm.ems.default'] = 'basedb'; 
    $app['orm.ems.options'] = [ 
     'basedb' => [ 
      'connection' => 'base', 
      'mappings' => $app['orm.em.options']['mappings'] 
     ], 
     'websitedb' => [ 
      'connection' => 'website', 
      'mappings' => $app['orm.em.options']['mappings'] 
     ] 
    ]; 

を私が接続したいのです。

これは私が立ち往生している場所で、私は知らないし、Silexのデータベース接続を再構成する方法を見つけることができません。誰もこれをやったことがありますか?

答えて

0

私はサイレックスでは、このような要求を持っていなかったが、あなたは常にデータベース

への接続を作成するために

$conn = Doctrine\DBAL\DriverManager::getConnection($params, $config); 

を使用することができます

関連する問題