2012-04-17 23 views
3

私はMagentoで問題があります。私はmagento.oneデータベースと2つのデータベースを接続したい、メインデータベースともう1つは店舗になります。私は を助けてください偽 を次の私のlocal.xmlがある.....私の接続は、ファイルアプリの/ etc/local.xmlであるit.Byこの時間を行う方法を知りません [mysql4]]> 2つのデータベースへのmagento接続

+0

http://blog.decryptweb.com/connect-database-magento/このリンクを試す – sulabh

答えて

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); 
} 

あなたは、特定の問題に遭遇した場合は私に知らせてください。

+0

助けてくれてありがとうございます。私はあなたのコードで非常に簡単にそれを行うことができました。 –

+0

ありがとうございます。良い仕事を続ける –

関連する問題