I have a complex data structure that means I have not been able to fully use relationships defined in schema.yml for my model.
Now I have some reporting queries which need to use tables from several databases.
Because of the complexity of the model these queries are written in raw sql. So I need to use the database names in the query in order to select the correct databases for various tables.
I am using symfony 1.4 and Doctrine 1.2
How can I extract the database names for my current environment (Prod, Dev, Test etc) from databases.yml in order to use them in the raw sql queries?
Im sure there must be a better way, but turns out you can get the DSN from sfDatabaseManager. So until I find a proper way, I’ve extended sfDatabaseManager to add the following getDsn method
Then in the model where I need to get the database name for a specific connection and environment:
Just need to explode / regex on the dsn then to get the dbname.
I would LOVE it if someone would post to tell me how rubbish this is, but of course only if they have a better solution! I have looked, and looked and looked….