2010年12月11日星期六

[fw-mvc] Simple way of reusing database configuration settings in Zend_Config

I have a number of databases. Rather than keep all of my site data all
in one database, I have the data semantically sectioned into separate
databases (using postgresql-9.1), i.e. blog, ecommerce, etc. While
this helps me keep all of my data organized, it's a hassle when it
comes to configuring database adapters. Here is what my
application.ini looks like:

; Pgsql 'trailers' database Resource Config
resources.trailersDb.adapter = "pdo_pgsql"
resources.trailersDb.params.username = "my_username"
resources.trailersDb.params.host = "localhost"
resources.trailersDb.params.password = "my_super_secrete_password"
resources.trailersDb.params.dbname = "trailers"

; Pgsql 'ecommerce' database Resource Config
resources.ecommerceDb.adapter = "pdo_pgsql"
resources.ecommerceDb.params.username = "my_username"
resources.ecommerceDb.params.host = "localhost"
resources.ecommerceDb.params.password = "my_super_secrete_password"
resources.ecommerceDb.params.dbname = "ecommerce"

; Pgsql 'blog' database Resource Config
resources.ecommerceDb.adapter = "pdo_pgsql"
resources.ecommerceDb.params.username = "my_username"
resources.ecommerceDb.params.host = "localhost"
resources.ecommerceDb.params.password = "my_super_secrete_password"
resources.ecommerceDb.params.dbname = "blog"

...etc.

As you can see, all of the adapter config params are the same EXCEPT
the database names. Is there a simple way to reuse config values and
just substitute the one I need to change? For example, I know this can
be done based on the APPLICATION_ENV variable [testing : production],
but what about in the example above? Or is my way of organizing
databases to unwieldy? What do the pros say?

--regards,
nathan

没有评论: