Magento 1.9 – How to Get Table Prefix

magento-1.9prefixtable

I have the following code in my install to create a table:

$installer->run(
    "CREATE TABLE IF NOT EXISTS `npcallnations_orders` (
        `id` INT AUTO_INCREMENT,
        `order` int,
        `status` int,
        `real_order_id` int,
        `customer` varchar(245),
        `fatdir` int,
        `created_at` DATETIME null,
        PRIMARY KEY (ID)
    )"
);

but if the magento has a table prefix, it will return an error when I try to use the collection. How can I do it so it will create correctly with prefix?

Best Answer

You can use:

Mage::getSingleton('core/resource')->getTableName('npcallnations_orders')
Related Topic