开发者

In Magento how do you get the database name?

How do you get the database name from Magento?

I have seen 开发者_StackOverflow中文版functions like the one below that can get the table name.

$orderItemTable = Mage::getSingleton('core/resource')->getTableName('sales/order_item');

I was hoping that there was some sort of function like this:

Mage::getSingleton('core/resource')->getDatabaseName();

Thanks in advance for any ideas.


Each module can specify it's own connection so you are right to go via a model.

$config = Mage::getResourceModel('sales/order')->getConnection()->getConfig();
// $config is an array
$dbname = $config['dbname'];

If you're only interested in the default a slightly more efficient way might be:

$dbname = (string)Mage::getConfig()->getNode('global/resources/default_setup/connection/dbname');


To get the db name try

Mage::getConfig()->getResourceConnectionConfig('default_setup')->dbname;

See How to get magento database details


It is always possible to get the current connection from Mage::getSingleton('core/resource')->getConnection('core_write'), quite specially if you use only one database.

$configArray = Mage::getSingleton('core/resource')->getConnection('core_write')->getConfig();
$db = $configArray['name'];

But it's comming with a zend adapter Zend_Config

// Create the object-oriented wrapper upon the configuration data
$config = new Zend_Config($configArray);
$db = $config->get('dbname');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜