Search code examples
codeigniterreplication

disconnect current database connection in controller function and connect another database in codeigniter


in my application/config/database.php i have multiple database connections..now currently database connection will be make as per in which city i get logged in.As per the city database connection will be created successfully...now what i have to do is inside a particular function i need to connect a replication database(for only that function i have connected the replication database)...i will connected that replication database connection successfully but the problem is it will connect for throughout my whole application..i need replication database connection for that function only...for rest of the controllers and functions i need to connect the database which i have connected as per the city.


Solution

  • Here i have come up with the solution of my problem i.e loading the replication database inside the constructor function of model instead of controller's constructor function which allows to load the replication database connection whenever it is needed.