Connect different database from Magento

piaoling  2012-07-13 14:09:12

Some of you might have worked on Magento.

I am listing here points for connecting another database from Magento.

1) Suppose your database for Magento Project is named ‘magento’.

2) There is one other database named ‘wp’.

3) For using this database inside Magento, you need to setup connection in ‘config.xml’ file which resides in ‘urmagentodirectory/app/etc’

4) In ‘config.xml’ there is a tag ‘’ inside which default connection is setup, you need to write this code under this.

?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
<wp_setup>
    <connection>
    <host>< ![CDATA[hostname]]></host>
    <username>< ![CDATA[username]]></username>
    <password>< ![CDATA[password]]></password>
    <dbname>< ![CDATA[wp]]></dbname>
    <model>mysql4</model>
    <initstatements>SET NAMES utf8</initstatements>
    <type>pdo_mysql</type>
    <active>1</active>
    </connection>
</wp_setup>
<wp_write>
    <connection>
    <use>wp_setup</use>
    </connection>
</wp_write>
<wp_read>
    <connection>
    <use>wp_setup</use>
    </connection>
</wp_read>

5) Now you can use this connection by following

?
1
2
3
4
<?php
$read = Mage::getSingleton('core/resource')->getConnection('wp_read');
$write = Mage::getSingleton('core/resource')->getConnection('wp_write');
?>

 

 

FROM:http://blog.decryptweb.com/connect-database-magento/

类别 :  magento(258)  |  浏览(4046)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: