2009-04-09 6 views
3

私はSymfonyプロジェクト用のDALとしてPropelを使用しています。アプリケーションが2つ以上のデータベースで動作するようには見えません。 db2はないが、唯一のdb1が生成され、私はphp symfony propel-build-modelを呼び出すときSymfonyで複数のデータベースがサポートされています

dev: 
    db1: 
    param: 
     classname: DebugPDO 
test: 
    db1: 
    param: 
     classname: DebugPDO 
all: 
    db1: 
    class: sfPropelDatabase 
    param: 
     classname: PropelPDO 
     dsn: 'mysql:dbname=bpodb;host=localhost' #where the db is located 
     username: root 
     password: #pass 
     encoding: utf8 
     persistent: true 
     pooling: true 


    db2: 
    class: sfPropelDatabase 
    param: 
     classname: PropelPDO 
     dsn: 'mysql:dbname=mystore2;host=localhost' #where the db is located 
     username: root 
     password: #pass 
     encoding: utf8 
     persistent: true 
     pooling: true 

は、ここに私のschema.ymlのだ:

db1: 
    lkp_User: 
    pk_User:      { type: integer, required: true, primaryKey: true, autoIncrement: true } 
    UserName:     { type: varchar(45), required: true } 
    Password:     longvarchar 
    _uniques: 
     Unique:     [ UserName ] 

db2: 
    tesco: 
    Id:     { type: integer, required: true, primaryKey: true, autoIncrement: true } 
    Name:    { type: varchar(45), required: true } 
    Description:   longvarchar 

そして、ここでdatabases.ymlのです。

どのようにすればこの問題を解決できますか?

答えて

6

I got this issue working!最も重要なことは、%dbname%.schema.ymlに従ってスキーマに名前を付ける必要があることです。このようにして、symfonyはymlを正しいデータベースに割り当てることができます。 、

symfony propel:build-all-load --connection=my_connection 

これは私のために働いて、それが役に立てば幸い:タスクを実行する際に

+2

それは悪いお尻です。ヒントをありがとう! –

1

また、あなたは、例えば、接続を指定する必要があります。

+0

こんにちは、私はあなたの提案を試みた---しかし動作しません.. – Graviton

1

Propel::getConnection('db2')を使用して、手動で接続を取得することもできます。

"db1"、 "db2"という名前はの接続名です。さまざまなログイン/許可(読み取り専用など)を使用して、同じデータベースに複数の接続を設定できます。

テスト目的には非常に適しています。別のデータベースを使用して同じ接続名で実行できます。それとあなたの生産データベースをクラッシュする方法はありません:)

関連する問題