在Symfony 1.2中如何从Propel中的database.yml文件中获取当前数据库名称? [英] In Symfony 1.2 how can I get the current database name from the database.yml file in Propel?
本文介绍了在Symfony 1.2中如何从Propel中的database.yml文件中获取当前数据库名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个原始的sql查询我需要运行,但数据库名称在每个环境中更改(live:db,dev db_test)
I have a raw sql query I need to run, but the database name changes in each environment (live: db, dev db_test)
我需要获取
如何获取当前的数据库名称?
How can I get just the current database name?
我使用的Propel ORM
I am using the Propel ORM
推荐答案
最初我认为这将是很容易通过 sfPropelDatabase :: getConfiguration ()
,但返回一个数组。因此,我不得不解析结果以获取数据,我认为可能有比这更好的方法:
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?
这篇关于在Symfony 1.2中如何从Propel中的database.yml文件中获取当前数据库名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文