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

  • Home
  • SEARCH
  • 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 6881179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:04:30+00:00 2026-05-27T05:04:30+00:00

I have an application where each subscriber gets their own ‘app’ folder within their

  • 0

I have an application where each subscriber gets their own ‘app’ folder within their own url eg.

www.domain.com/1234 subscriber1
www.domain.com/2345 subscriber2

now the db connection is configured in a class in config/database.php. I want to be able to change the database used based on the url (eg. /1234 = db_1234).

How would I achieve this?

Thanks

BTW I am using CakePHP 2.0

  • 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-05-27T05:04:30+00:00Added an answer on May 27, 2026 at 5:04 am

    My previous solution was a load of rubbish. So I thought about attacking the problem from a different angle. My DATABASE_CONFIG class (/app/Config/database.php) now looks like this:

    class DATABASE_CONFIG {
    
      public $default = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => '127.0.0.1',
        'login' => 'xxxx',
        'password' => 'xxxx',
        'database' => 'xxxx',
        'prefix' => '',
        'encoding' => 'utf8',
      );
    
      public $site_one = array(
        'datasource' => 'Database/Mysql',
        'host' => '127.0.0.1',
        // ...  
      );
    
      public $site_two = array(
        'datasource' => 'Database/Mysql',
        'host' => '127.0.0.1',
        // ...
      );
    
      public function __construct()
      {
        if (strpos(env('HTTP_HOST'), 'site_one') !== false) {      
    
          // use site_one database config
          $this->default = $this->site_one;
    
        // elseif site_two
        } elseif (strpos(env('HTTP_HOST'), 'site_two') !== false) {
    
          // use site_two database config
          $this->default = $this->site_two;
        }
      }
    
    }
    

    When Cake loads, the construct is now called automatically, and this sets the ‘default’ database connection dependent on the host.

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

Sidebar

Related Questions

I have an application where for each object the user can specify his own
Is it best to have each application with its own copy of the ZF
I have PHP application that contain three small applications. Each application have own users
I have a rails application where each user has a separate database. (taking Joel
I have an application in which users interact with each-other. I want to visualize
I have an application with 5 UIViewController s each inside a corresponding UINavigationController ,
I have two application that need to talk to each other. App1 needs to
I have an application where I receive each data 40.000 rows. I have 5
I have various objects in application,and each has isvalid method to test if values
I have an application that has many different types of objects that each persist

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.