2009-04-09 53 views
3

我使用Propel作爲我的Symfony項目的DAL。我似乎無法讓我的應用程序跨兩個或更多數據庫工作。在Symfony中支持多個數據庫

這裏是我的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裏:

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 

當我打電話php symfony propel-build-model,只有db1產生,db2不是。

任何想法如何解決這個問題?

回答

6

I got this issue working!最重要的是你必須根據%dbname%.schema.yml命名你的模式。通過這種方式,Symfony將能夠將ymls分配給正確的數據庫。

+2

這是壞驢。謝謝你的提示! – 2009-04-09 14:04:15

1

而且運行任務時,你應該指定例如連接:

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

這爲我工作,希望它幫助。

+0

你好,我試過你的建議---但是不行。 – Graviton 2009-08-23 11:13:04

1

您還可以使用Propel::getConnection('db2')來手動檢索連接。

請記住,您所謂的「db1」,「db2」是連接名稱。您可以通過各種登錄/權限(如只讀等)連接到同一個數據庫。

它非常適合測試目的:您可以使用具有不同數據庫的相同連接名稱進行測試。沒有辦法讓你的生產數據庫崩潰:)