0

I will be shifting my code base to the new 2.0 framework and just had a few questions on the following points

My urls will be as follows

  • example.in/city1
  • example.in/city1/admin
  • example.in/city2
  • example.in/city2/admin

I would like to know what would be the best way to switch the database based on the city in the url? .

In my webroot i will have directories like city1, city2 each containing an index.php file which points to the single code base.

Now i only need a way to switch the database based on the url entered.

Regards, Sheldon

6
  • 1
    why would you whant different databases based on cities ? Commented Mar 31, 2011 at 7:58
  • 1
    I'd rethink this approach entirely. One database, use a table for each city (or better yet, several tables with appropriate relationships). I can't think of a single reason you'd need to do it like this Commented Mar 31, 2011 at 10:12
  • @poelinca, @ross The main reason i was thinking of having multiple databases for the each city is that we have a support center as well as logistics team to cater to customers in each city. So i thought that keeping each citys data in separate databases would make more sense Commented Mar 31, 2011 at 16:36
  • 1
    bad decision ( atleast from my point of view ), tough it would make sence ( and it would be more fun ) to design such a database structure that allows you to instantly add countries over the cities, worlds over countries, planets over worlds ... you whont need directories but routes, and users, and category trees ( cityes ... ), and acl and resources and ... let you're app be easy extendable with 2 click instead of creating another database and directories and configs ... Commented Mar 31, 2011 at 17:19
  • @poelinca My site currently operates in only 1 city and the database has about 150 tables containing information for that city. According to you the better more extendable solution would be better for me to rework all tables structures in database to now have an association with say cityid. So when i switch to another city the data will be filtered out using the city id as the key. – Commented Mar 31, 2011 at 17:36

1 Answer 1

1

I completely agree with @poelinca and @Ross, you should definitely consider rethinking your design.

however for reference issues this topic was already covered in the CodeIgniter forums pretty well over here

Basically you just configure another set of $db items per connection and then request the connection based on those configuration parameters by the CodeIgniter framework, by providing the new $db as a parameter for the DB class constructor.

Sign up to request clarification or add additional context in comments.

1 Comment

My site currently operates in only 1 city and the database has about 150 tables containing information for that city. According to you it would be better for me to rework all tables structures in database to now have an association with say cityid. So when i switch to another city the data will be filtered out using the city id as the key.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.