我开发了一个模块来从 Magento 访问外部数据库,当我在干净的 Magento 安装上测试模块时它工作正常,但是当我在使用表前缀的干净 Magento 安装上测试它时它失败了,因为它添加了前缀模块上使用的外部表的名称。
有没有办法禁用模块上使用的所有外部表的表前缀?
我希望该模块可以在有或没有表前缀的安装上工作。我试过添加:
<table_prefix><![CDATA[]]></table_prefix>
在我模块的 config.xml 部分下,没有任何运气。
任何想法?
我开发了一个模块来从 Magento 访问外部数据库,当我在干净的 Magento 安装上测试模块时它工作正常,但是当我在使用表前缀的干净 Magento 安装上测试它时它失败了,因为它添加了前缀模块上使用的外部表的名称。
有没有办法禁用模块上使用的所有外部表的表前缀?
我希望该模块可以在有或没有表前缀的安装上工作。我试过添加:
<table_prefix><![CDATA[]]></table_prefix>
在我模块的 config.xml 部分下,没有任何运气。
任何想法?
Ox3,一种选择是为您自己的模块创建连接,例如:
<?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>
然后你可以在你的代码中调用它:
$new_conn = Mage::getSingleton('core/resource')->getConnection('mymodule_read');
我希望它有所帮助。干杯!