1
votes

I developed a module to access an external DB from Magento, when I test the module on a clean Magento install it works fine, but it fails when I test it on a clean Magento install that uses a table prefix, as it adds the prefix to the name of the external tables used on the module.

Is there a way to disable the table prefix for all the external tables used on the module?

I would like the module to work on installations with or without table prefix. I have tried adding:

<table_prefix><![CDATA[]]></table_prefix>

Under my section on the config.xml of my module without any luck.

Any idea?

1

1 Answers

0
votes

Ox3, one option is to create a connection for your own module, e.g.:

<?xml version="1.0"?>
<config>
    <modules>
        <Vendor_Mymodule>
            <version>0.1.0</version>
        </Vendor_Mymodule>
    </modules>
    <global>
        <models>
            <mymodule>
                <class>Vendor_Mymodule_Model</class>
            </mymodule>
        </models>
        <resources>
            <mymodule_write>
                <connection>
                    <use>mymodule_setup</use>
                </connection>
            </mymodule_write>
            <mymodule_read>
                <connection>
                    <use>mymodule_setup</use>
                </connection>
            </mymodule_read>
            <mymodule_setup>
                <connection>
                    <host><![CDATA[localhost]]></host>
                    <username><![CDATA[username]]></username>
                    <password><![CDATA[password]]></password>
                    <dbname><![CDATA[db_name]]></dbname>
                    <model>mysql4</model>
                    <initStatements>SET NAMES utf8</initStatements>
                    <type>pdo_mysql</type>
                    <active>1</active>
                </connection>
            </mymodule_setup>
        </resources>
    </global>
</config> 

Then you can call it into your code:

 $new_conn = Mage::getSingleton('core/resource')->getConnection('mymodule_read');

I hope it helps. Cheers!