views:

138

answers:

1

I have a raw sql query I need to run, but the database name changes in each environment (live: db, dev db_test)

I need to get the current database name from the databases.yml file.

How can I get just the current database name?

I am using the Propel ORM

+1  A: 

Initially I thought this would be pretty easy via sfPropelDatabase::getConfiguration() but that returns an array. As such, I had to parse the result to get the data, and I think there's probably a better way than this:

$propel_config = sfPropelDatabase::getConfiguration();
preg_match('/dbname=([^;]+);/', $propel_config['propel']['datasources']['propel']['connection']['dsn'], $matches);
echo $matches[1];

Anyone got anything better?

Raise
It would really be nice if there was more control beside just getting a dump for the yaml file.I had to remove the ';' from the regex above since the dbname was the last character and it could not find it at the end of the string.
Failpunk