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 8709153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:18:01+00:00 2026-06-13T04:18:01+00:00

I am using codeigniter to develop my web based application. This will be used

  • 0

I am using codeigniter to develop my web based application. This will be used by various different clients and each will have there own database but same codebase.

I want to be able to set the name of database in database.php based on the clients who access it i.e based on the url. So if clientA.com access its then it should set the database name to clintA and if clientB.com access it then it should set it to clientB.com.

Any idea as how should I approch this.

  • 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-13T04:18:02+00:00Added an answer on June 13, 2026 at 4:18 am

    There are several possible ways, but probably the easiest is to use database groups in your config file. In your application/config/database.php file use a multi-dimensional array to create different groups for each of your clients. So you could have:

    $db['clientA']['hostname'] = ...
    $db['clientA']['username'] = ...
    etc...
    $db['clientB']['hostname'] = ...
    $db['clientB']['username'] = ...
    etc...
    

    Now in your application you can just pass the desired group to your load command:

    $this->load->database('clientA');
    

    Now combine that with getenv to grab the host name and you should be all set:

    $clientHost = getenv('HTTP_HOST');
    $this->load->database($clientHost);
    

    Of course there could be more logic needed, but that should get you started.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using codeigniter php MVC framework to develop a web application. I have
I am using Codeigniter to develop an application, and have been reading bits about
I'm using CodeIgniter to develop a new web app, and I'd like to create
I'm using CodeIgniter 2 (latest build) ...let's say I have this query: $CI->db->select(FileName, GUID,
I'm trying to develop a web based digital asset management application. I'm planning to
I'm using codeigniter for my web application which is having user registration feature. And
Recently I have started working with Codeigniter framework in order to develop RESTFul web
i have built application using codeigniter, my controller name is userReg , in controller
Using Codeigniter and Datamapper : I have 2 tables: tags and clients . Clients
I'm using codeigniter for this project. I have a search form and search form

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.