我在其 config.xml 文件中创建了一个新模块forumprodposts我添加了以下 xml。在控制器中,我添加了此代码
$sql = "SELECT * FROM comments";
$conn = Mage::getSingleton('core/resource')->getConnection('forumprodposts_read');
$data = $conn->fetchAll($sql);
但是上面的代码抛出了comments不是核心数据库的表的错误。我认为在我的 xml 中有一些错误,因此没有建立与prodcomments数据库的连接。
<resources>
<forumprodposts_write>
<connection>
<use>prodcomments_database</use>
</connection>
</forumprodposts_write>
<forumprodposts_read>
<connection>
<use>prodcomments_database</use>
</connection>
</forumprodposts_read>
<forumprodposts_setup>
<connection>
<use>core_setup</use>
</connection>
</forumprodposts_setup>
<forumprodposts_database>
<connection>
<host><![CDATA[localhost]]></host>
<username><![CDATA[username]]></username>
<password><![CDATA[password]]></password>
<dbname><![CDATA[prodcomments]]></dbname>
<model>mysql4</model>
<type>pdo_mysql</type>
<active>1</active>
</connection>
</forumprodposts_database>
</resources>