Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8640705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:20:42+00:00 2026-06-12T11:20:42+00:00

Does someone knows the best practice for using 2 different database in my application?

  • 0

Does someone knows the best practice for using 2 different database in my application?

I need to store data in both databases which are differently located (host,username,password , all does change).

I’m planning to create models as usual, and in construct set the db host,name,pass etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:20:44+00:00Added an answer on June 12, 2026 at 11:20 am

    I’m not sure if you call this “best” way, but a way, as described in the tutorial, is this,

    in the database file, you have the default configuration, a part of which is:

    $db['default']['hostname'] = "localhost";
    $db['default']['username'] = "user";
    $db['default']['password'] = "database";
    $db['default']['database'] = "db1";
    

    now you can create another group, say we call it group1 and we want it to have everything the same as the default database settings except for the name, so you can do

    $db['group1']=$db['default'];
    $db['group1']['database']="db2";
    

    then, when you want to use the second database, just go

    $DB2 = $this->load->database('group1', TRUE); 
    

    and then, instead of $this->db->foo() , you will do $DB2->foo()

    alternatively (as suggested in comments by sbaaaang), you can do $this->db=$DB2; to keep everything the same

    and you can extend this to multiple groups like this

     $DB1 = $this->load->database('group1', TRUE); 
     $DB2 = $this->load->database('group2', TRUE); 
     ...
     $DBn = $this->load->database('groupn', TRUE); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does someone knows C# best practice about the way to define attribute visibility (private
Does someone knows the image-crop which correctly works with the 'dynamically changed in the
Does someone knows why the mysql_real_escape_string() function adds three backslashes before quotes, or double
Does someone knows how can I capture my computer screen to a video file?
Does someone knows how to calculate the total hours between 2 times? For example
I’m having a problem getting the data from my database which I created to
I get very different results when trying to find the best AR(p) model using
Does someone know the best approach on how to convert a text into image
Does someone know a simple way to set the default zoom and latitude/longitude with
Does someone know how to find the longest common subsequence of a set of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.