Welcome Guest, Not a member yet? Register   Sign In
Using another database
#1

[eluser]ninjayan[/eluser]
Hello everyone. This is my code for the ignited datatables..


Code:
$this->load->library('datatables');
  $this->datatables
     ->select("doc_ref, source_doc, subject_doc, enter_doc, date_doc")
     ->from("tbl_doc")
     ->add_column("Action",
        "<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' />
        </button>
        &lt;/form&gt;
        ",
        "doc_ref"
        );
  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!
#2

[eluser]PravinS[/eluser]
check the url

http://ellislab.com/codeigniter/user-gui...cting.html
#3

[eluser]ninjayan[/eluser]
as you can see on my code, there is no
Code:
$this->db->query();

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
#4

[eluser]PravinS[/eluser]
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

http://ellislab.com/codeigniter/user-gui...ation.html

hope this will help you
#5

[eluser]ninjayan[/eluser]
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
#6

[eluser]Unknown[/eluser]
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

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

Then to use it simply

Code:
$this->db_2->query();

Hope this helps. Smile
#7

[eluser]ninjayan[/eluser]
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




Theme © iAndrew 2016 - Forum software by © MyBB