2

I need to be able to add/edit/delete records whose data structure is somewhat complex and involves a lot of business rules for each database operation. For example:

  • Some inserts are simple INSERTs, while others may be INSERT IGNORE depending on certain conditions
  • Delete operations may or may not trigger addition DB operations
  • etc

Furthermore, due to the complexity of the data structure and a few other reasons (e.g. not wanting this to be coupled to EE so that other CMS can interact with it in the future), I want all this data to be on a separate database.

I'm still not completely sure what an addon can or cannot do. So, here are some questions I have before getting too deep into this:

  1. Is it possible to create some sort of addon whose data is stored on a different database?
  2. Since this won't be using Channels, how would I make my back end interfaces appear in the Control Panel?
  3. Will I be able to loop through the entries like I do with Channel entries (using tag pairs)?
5
  • Why do you need a separate database vs. just creating your own data tables? Commented Dec 11, 2012 at 1:37
  • To eliminate coupling. Say I wanted this to also work with WordPress. Should I force WordPress to access EE's database? It's not a strong requirement, but it would be good if I could do this. Don't addons allow you to define your own DB connection stuff? Commented Dec 11, 2012 at 1:54
  • You can define the DB connections in the config, not sure about multiple db's. That's a little out my area of expertise, which is why I asked. Commented Dec 11, 2012 at 1:56
  • A number of ISPs ONLY provide you access to one database, but you can create as many data tables as you like. Most add-ons use the config.php/database.php files to get database connection data. Many of the add-ons that are Modules, store data in their own data tables, and create their own processing logic. For example, FreeForm Pro from Solspace doesn't use channel data. But integrating it into the EE Control Panel, does assume coupling with EE. You could create other versions for other CMSs, but each would be coupled to the CMS, unless you build a stand-alone app. Commented Dec 11, 2012 at 7:33
  • Thanks. I wanted the data to be decoupled from the CMS. The data is actually going to be used by another application (primarily displaying it). I just wanted EE to handle the management of the data. What if the data had an API and the module interacted with the data through the API? Commented Dec 11, 2012 at 11:21

1 Answer 1

3

Is it possible to create some sort of addon whose data is stored on a different database?

Sure, I'm pretty sure this should work (based on the CodeIgniter docs):

$config = array(
    'hostname' => "localhost",
    'username' => "myusername",
    'password' => "mypassword",
    'database' => "mydatabase",
    'dbdriver' => "mysql",
    'char_set' => "utf8",
    'dbcollat' => "utf8_general_ci"
);    
$this->EE->custom_db = $this->EE->db->load->database($config);   
// Now use $this->EE->custom_db->query(), etc

Since this won't be using Channels, how would I make my back end interfaces appear in the Control Panel?

You'd have to build the interfaces yourself, using "view" files inside your add-on, which can then use EE's helper classes to build forms, tables, etc for display. (See the module tutorial for some guidance.)

Will I be able to loop through the entries like I do with Channel entries (using tag pairs)?

Yes, the key to that is just having your data in a multi-dimensional array, and using this->EE->TMPL->parse_variables() (see docs).

1
  • Thanks Derek. I'm going through your answer to see if I understand everything. Commented Dec 12, 2012 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.