Welcome Guest, Not a member yet? Register   Sign In
same application, multiple custumers (of which each one has it's own database)
#1

[eluser]CI beyond[/eluser]
Hi,

I'm sure this has come up before, but the search results only showed solutions regarding the system_folder.

I've written an application which will be used by multiple customers. So each customer has its own application and database. As the number of customers is growing it's getting more and more tiresome (not to mention, error-prone) to update all these sources in case of updates/fixes.
I'm looking for a way to have a single, central application and a database.php per application. All applications live on the same server and are accessed using name-based virtual hosts.

So. to sum it all up:
- 1 application
- multiple customers,
- each customers has it's own database (hence the only difference between all instances is config/database.php

Any ideas on how to approach this?

Thnx for any insights!
#2

[eluser]skattabrain[/eluser]
newbie to ci here, but can you if/else in the config file? say with a session variable, then loading their db settings?
#3

[eluser]CI beyond[/eluser]
hmmz, i guess it's possible, i can determine which database to load by examining the $_SERVER[ 'HTTP_HOST' ] in database.php. It should work, but it's a bit unelegant because if an url changes you have to change the database.php as well.

not bad though, keep them coming Wink
#4

[eluser]Michael Wales[/eluser]
Surely you have another way of identifying which user is on other than the URL, correct?

If not, I would highly suggest creating a central database for account information/authentication. Use this database for the initial login, then users can jump on over to their own database to interface with the application itself. This will give you an identifier (outside of the URL) to determine which database to use via a conditional statement in database.php (actually, I would pull it out of that file so it doesn't get to bloated, but the same concept).
#5

[eluser]CI beyond[/eluser]
each customer is a company with numerous users Wink I'd rather avoid writing extra stuff for authentication and redirecting. I'm simply looking for a way to put all these redundant sources in 1 place and somehow still manage to connect to the corrct database.

To be clear: company A could have users named 1, 2 and 3, while company B could also have users named 1, 2 and 3. Even if i would write some central database this would require the users to select from which company they're from which is not only inconvenient but also not very sensitive in light of privacy Smile

I was more thinking along the lines of some smart symlinking on the webserver.
#6

[eluser]ccachor[/eluser]
I would setup a central database with connection information for each db. I would also keep in mind if you keep adding customers at some point you might need a dedicated db server so add a field in your db for that. Then if theyre all running the same app with just different data this would solve your problem. Connect to your central database (say users or companies) and look up the connection info and pass that data into a second connection. Then setup a workgroup to assign users to different companies or accounts. Hope that helps
#7

[eluser]skattabrain[/eluser]
exactly what i was thinking ... if clientID = '123' ... then load the db settings for clientID '123'.

so what happens when you modify the database? you have to then do that for every customer? yuck.

can't you simply pull the client's specific data only out of the same database? simplifying your administration tasks.
#8

[eluser]CI beyond[/eluser]
But that would still require me to parse connection information doesn't it? In that case i'd better extend database.php and do the parsing/selecting there.

Are there any objections (security-related or otherwise) against this approach? Apart from 'not elegant' i can't think of anything else.

Thnks for your thoughts! Smile
#9

[eluser]ccachor[/eluser]
Connect to the first database, look up the connection info based on the domain or subdomain, then pass in the connection info into another model. http://ellislab.com/codeigniter/user-gui....html#conn

Then you have simple administration and when you have lots of customers you won't have a mess to deal with. That stuff will snowball...
#10

[eluser]skattabrain[/eluser]
[quote author="CI beyond" date="1204079657"]But that would still require me to parse connection information doesn't it? In that case i'd better extend database.php and do the parsing/selecting there.

Are there any objections (security-related or otherwise) against this approach? Apart from 'not elegant' i can't think of anything else.

Thnks for your thoughts! Smile[/quote]

with most lamps i've been on ... each virtual host still accesses the same mysql install ... so as long as you know the user/pass ... any account on the box can access the same database. is this what your asking?

[quote author="ccachor" date="1204080290"]Connect to the first database, look up the connection info based on the domain or subdomain, then pass in the connection info into another model. http://ellislab.com/codeigniter/user-gui....html#conn

Then you have simple administration and when you have lots of customers you won't have a mess to deal with. That stuff will snowball...[/quote]

agree




Theme © iAndrew 2016 - Forum software by © MyBB