Welcome Guest, Not a member yet? Register   Sign In
Calling $this->load->database() multiple times
#1

[eluser]TheBenno[/eluser]
I have read the user-guide thoroughly, but I did not see an answer to my question: Is it acceptable to call $this->load->database() multiple times in a single page load? I called it twice in a row like so:

Code:
$a = $this->load->database('default', TRUE);
$b = $this->load->database('default', TRUE);

and $a == $b but $a !== $b. It would be extremely bad if calling it twice in a row creates 2 connections to the database, as you will very quickly get "Too Many Connection" errors from your DB unnecessarily.


The reason I ask is: not all of my pages use all of my databases. I would like to connect only the the databases I need for each specific page load. I feel the best way to do this would be to connect to the a database within the model-methods which requires that database. That way i don't need to list out the databases at the top of each controller method, instead i just call the model methods i need, and they connect to the appropriate databases lazily (like MDB2 is capable of doing with its singleton() method). My worry is that if i do it this way I will create many more than 1 connection to the same database per page load, when really the connection could be cached. I could always build an MDB2 library into codeigniter, but I would prefer to use their database libraries.


Can anyone help?


Thanks!


Messages In This Thread
Calling $this->load->database() multiple times - by El Forum - 06-07-2010, 12:56 PM
Calling $this->load->database() multiple times - by El Forum - 06-07-2010, 01:30 PM
Calling $this->load->database() multiple times - by El Forum - 06-07-2010, 01:33 PM
Calling $this->load->database() multiple times - by El Forum - 06-07-2010, 03:08 PM
Calling $this->load->database() multiple times - by El Forum - 06-08-2010, 01:08 AM
Calling $this->load->database() multiple times - by El Forum - 06-08-2010, 01:24 AM
Calling $this->load->database() multiple times - by El Forum - 06-08-2010, 06:45 AM
Calling $this->load->database() multiple times - by El Forum - 06-23-2010, 03:04 AM
Calling $this->load->database() multiple times - by El Forum - 06-23-2010, 03:35 AM
Calling $this->load->database() multiple times - by El Forum - 06-23-2010, 03:59 AM
Calling $this->load->database() multiple times - by El Forum - 01-12-2011, 04:13 PM
Calling $this->load->database() multiple times - by El Forum - 01-12-2011, 04:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB