Using another database |
[eluser]ninjayan[/eluser]
Hello everyone. This is my code for the ignited datatables.. Code: $this->load->library('datatables'); 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!
[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
[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
[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
[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.
[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. |
Welcome Guest, Not a member yet? Register Sign In |