3

Magentoに問題があります。2つのデータベースをmagentoに接続したい。1つのデータベースがメインデータベースになり、もう1つがストア用になります。方法がわかりません。この時点で、接続はファイルapp / etc /local.xml.....にあります。私のlocal.xmlは次のとおりです。false[mysql4]]>1を助けてください。

4

1 に答える 1

2

私が実装したものよりも洗練されたソリューションがあるかもしれませんが、私の方法は機能します。これは、osCommerceのインポート/エクスポートモジュールに対して行いました。


/httpdocs/app/etc/config.xml

        <!-- osCommerce db/read/write -->
        <oscommercedb>
            <connection>
                <host>localhost</host>
                <username>root</username>
                <password>pass</password>
                <dbname>oscommerce_database_name</dbname>
                <model>mysql4</model>
                <initstatements>SET NAMES utf8</initstatements>
                <type>pdo_mysql</type>
                <active>1</active>
            </connection>
        </oscommercedb>
        <oscommercedb_write>
            <connection>
                <use>oscommercedb</use>
            </connection>
        </oscommercedb_write>
        <oscommercedb_read>
            <connection>
                <use>oscommercedb</use>
            </connection>
        </oscommercedb_read>
        <!-- end osCommerce db -->

これにより、モデル内で呼び出すことができoscommercedbます。上記のコードは<resources>ブロック内に入ります。

モデルを見てみましょう。


/httpdocs/app/code/local/Company/Extension/Model/OsCustomers.php

class Company_Extension_Model_OsCustomers extends Mage_Core_Model_Abstract
{

protected $_name = 'customers'; // name of the table

/**
 * Returns rowset of tables for customers
 *
 * @return Zend_Db_Table_Rowset
 */
public function getAllOscommerceCustomers()
{
    $read = Mage::getSingleton('core/resource')->getConnection('oscommercedb');

    $stmt = $read->select();

    $stmt->from(array('c' => 'customers'))
         ->join(array('a' => 'address_book'), 'a.address_book_id = c.customers_default_address_id')
         ->joinLeft('zones', 'zones.zone_id = a.entry_zone_id')
         ->join('countries','a.entry_country_id = countries.countries_id', array('countries_iso_code_2'));

    return $read->fetchAll($stmt);
}

特定の問題が発生した場合はお知らせください。

于 2012-04-17T13:40:22.697 に答える