Welcome Guest, Not a member yet? Register   Sign In
Help with database load design
#1

The current design:
- I'm using v2.2 (don't have time just now to upgrade)
- The application is multi-tenant, with each tenant having separate database
- The correct "tenant" database name for each authenticated user is determined and stored in the user's session data
- I have a custom Model class, extending CI_Model, that defines a "tentantdb" property
- In the constructor of this class the database config is defined, loaded ("$this->load->database($config, TRUE)"), and stored in the tenantdb property
- All model database actions are then performed against $this->tenantdb

It works, but ...
I have some controllers that load a large (40 or so) number of models. As each model is loaded a new connection to the database is created. This is causing database connection limits to be reached.

Ideally I'd like to create the db connection outside the controller (at an "application" level) and then pass it to the model during construction, allowing the same connection to be reused. However, I'm a struggling to identify the best way of achieving this. Any guidance would be much appreciated.
Reply


Messages In This Thread
Help with database load design - by NickBrown1968 - 08-09-2017, 07:38 AM
RE: Help with database load design - by Diederik - 08-11-2017, 02:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB