Formarly Known as The Three Tree External Database Connector
Magento External Database Connector module will be helpful for the “Developers” who want to connect to the external Database server (other than the database used by Magento). This module will help the developer to set up a connection object (Read & Write) with the configuration configured in Admin Settings and use that connection to do database transactions on external database.
All you have to do is set the settings of your external database connection in your Magento Settings and extend your model/collection class with the class of this module and use other codes as you have been using in Magento to select/update/delete records.
It will be as simple as Mage::getModel(‘mymodule/mymodel’)->setData(‘name’,'The Next Tree’)->save()
Here is the explanation of how you can use the External Database Connector module’s classes to define your
- Model
- Resource Model
- Collection
Lets take a simple example. Say you have a table (of course in an external database) named tbl_magician, which has two just two columns id and name. First thing set up an entity definition in the config.xml file of your module or you can add in this module’s config as well.
<entities>
<!-- Add As many tables config here -->
<magician> <!-- Table alias -->
<table>tbl_magician</table> <!-- Actual Table Name -->
</magician>
<!-- Add As many tables config here -->
</entities>
Model Defination
All of your Model that uses the external source has to be extended by Sp_Edb_Model_Abstract. If you see on this class you can find that the connection has been established based on the settings you do on Magento backend. An example for your model class will be something like this.
<?php
class Sp_Edb_Model_Magician extends Sp_Edb_Model_Abstract
{
/**
* Initialize resources
*/
public function __construct()
{
parent::__construct();
$this->_init('edb/magician);
}
}

If you are wondering where to set up your connection settings go to System–>Configuration–>SP EDB and add your settings there.
Resource Model
Similary your resource model should extend one another class of the module as shown below.
<?php
class Sp_Edb_Model_Mysql4_Magician extends Sp_Edb_Model_Mysql4_Abstract
{
protected function _construct()
{
$this->_init('edb/magician', 'id');
}
}
Collection
As you might have already guessed yes..! collection also needs to be extended by one another class of the module as below
<?php
class Sp_Edb_Model_Mysql4_Magician_Collection extends Sp_Edb_Model_Mysql4_Collection_Abstract
{
/**
* Local constructor
*
*/
protected function _construct()
{
$this->_init('edb/magician');
}
}
All those parent classes used are themselves extended from the classes which Magento uses for Model or Resource or Collection. So there is no any functionality missing and you can use the same old methods for insert/update or select.
After setting up all these classes you can now just freely use these functions without keeping external connection in mind.
$model = Mage::getModel('edb/magician');
// To save
$model->setName('The three Tree')->save();
$model->setName('TTT')->save();
// Get Collection
$collection = $model->getCollection();
$collection->getSelect()->where('main_table.id = ?', 1);
If you have any confusion we would be happy to address that.The module is now available on Magento Connect.
Thank you for this great stuff!
However a few minor things are unclear for me.
If you could attach a simple demo implementation project, that would be great.
That’s really shwred! Good to see the logic set out so well.
Hahahaha. I’m not too brghit today. Great post!
Is it normal that the Magento table prefix gets added on queries to the external connection?
Yeah that’s what I’m talknig about baby–nice work!
Plese tell me above step in detail .
Which config file I need use app/etc/config.xml?
Where is the Model Defination?
How can I create Resource Model?
Where I create Collection class?
Where and how I need to check connection?
Thanks for sharing. Always good to find a real exrept.
Ok i get it what i want to do thaks.
But now the problem is
When i go to System–>Configuration–>TTT EDB 404 page not not found error is coming & left side menu allso not showing.I also made changes in config.xml of that module.
Any solution
After installation of the module please log out of the Magento admin and then view the configuration. I hope your problem will be solved. And please reply if it works. Thanks.
thanks for reply,
Its still showing same error.
I am again reinstalling & log out but no chage plse help me out.
I m still stuck on that issue.
Or tell me any other solution for external db connection I really need it boss.
Thanks…………..
If you’re reaindg this, you’re all set, pardner!
Glad I’ve finally found somhetnig I agree with!
Thanks alot – your answer solved all my prolbmes after several days struggling
Hello,
I have a magento store in which I gather different stores but my store function like a one store. Instead of uploading and updating the products I wud like to conect either to a feed either to their databases and once they change their price they will automaticly change in my store. Wud like to know if your extension does what I need.
Thank you,Anna
I am sorry this extension does not do that…but can be helpful if you build a module implementing this module.
You’re the one with the brains here. I’m wahtcing for your posts.
A bit surprised it seems to simple and yet uesful.
That addresses several of my concerns acutally.
Thanks for the share!
Nancy.R
That’s raelly thinking out of the box. Thanks!
That’s relaly thinking out of the box. Thanks!
Hi,
could you tell me how to get last insert id ?
BR,
Isuru
Thanks for sharing your opinion here. I really value it.
Hey mate! I quite agree with your opinion.
Glad to read this blog! Keep it going!
Hi Subesh,
Thanks for the gr8 post..!!!
but I have certain doubs as what exactly means external database?
Can we use Oracle as an db & connect magento wih that?
If it’s possile then plz tell me steps for the same..
Thanks..
Hi Prat,
This module only works for MYSQL DB. This might be helpful with integrating Magento with external system which used MYSQL.