CodeIgniter Forums
Using another database - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Libraries & Helpers (
+--- Thread: Using another database (/showthread.php?tid=58721)

Using another database - El Forum - 07-12-2013

Hello everyone. This is my code for the ignited datatables..

     ->select("doc_ref, source_doc, subject_doc, enter_doc, date_doc")
        "<form id='disable_form' acti method='post' target='_blank'>
        <input type='hidden' value='$1' id='reference_number' name='reference_number' readonly>
        <button type='submit' class='no_btn' title='View'>
        <img src='$base_dir/assets/img/execute.png' class='left' />
  echo $this->datatables->generate();

I updated CI's db config and added another database connection and I want to use that in the ignited datatables. How can I do that? Thanks in advance!

Using another database - El Forum - 07-12-2013

check the url

Using another database - El Forum - 07-12-2013

as you can see on my code, there is no

its just $this->datatables->select and its using the default db connection. my question is how can i use the other db connection instead of the default one. i didn't find the solution on the url given. correct me if im wrong

Using another database - El Forum - 07-12-2013

Search "Connecting to Multiple Databases" in above link page, they have shown how to use two database connections.
But before this you need to add database configuration of your two databases in database configuration file, for that refer following link

hope this will help you

Using another database - El Forum - 07-12-2013

Yes, I understand that. I already configured my database config file to connect to another database. My problem is how to call that db config that will connect to the second database IN IGNITED DATATABLES.

In Ignited Datatables, you query at the controller and not at the model. To fetch some data, we do it like this...

$this->datatables->select(bla bla)->from('table2');

As you can see, it is different from the active record like

$this->db->query(); db1
$this->db_2->query(); db2

Using another database - El Forum - 07-13-2013

Every time that you wish to use the second db it must be called at the begging of the model or at least in the function you are working on.

First you need to load it like this

$this->db_2 = $this->load->database('db_2', TRUE);

Then to use it simply


Hope this helps. Smile

Using another database - El Forum - 07-13-2013

Yes you are right! But I am using Ignited Datatables which the query is done in controller and not in model. That's how it works. As you can see on my code at the top. Smile