views:

76

answers:

1

Hi,

I am required to work on a php project that requires the database to cater to multiple users. Generally, the idea is similar to what they have for carbonmade or basecamp, or even wordpress mu. They cater to multiple users, whom are also owners of their accounts. And if they were to cancel/terminate their account, anything on the pages/database would be removed.

I am not quite sure how should I design the database? Should it be:

  • separate tables for individual user account
  • separate databases for individual user account
  • or otherwise?

Kindly advise me for the best approach to this issue. Thank you very much.

A: 

How many users are we talking about?

Offhand, I like the idea of having a separate database for each user account. There are many advantages:

  • You can keep the schema (and your application code) simple
  • If a user ever wanted a copy of their database you could just dump it out and give it to them
  • You can easily take care of security by restricting access to each database to a given user account
  • You may be able to scale out more easily by adding more database servers, since you are using separate databases (there would be no common tables used by all users)

Of course, this could be a bit painful for you if you need to deploy updates to hundreds of databases, but that's what automated scripting is for.

The idea of having separate tables for each user seems like a coding nightmare. Each time you reference a shared table you will have to modify the name to match the current user's copy.

Justin Ethier
I am looking into maybe 100 users initially, and consistently having new users, e.g. free users. Based on your recommendation, does it mean that I just need a default database for the portal site to store basic info regarding the accounts, and then separate databases for individual account?
jl
Sure, that sounds reasonable.
Justin Ethier
How about if I need to store the members of all user accounts? So if we are talking about wordpress mu blogs, for instance. Say if I have a visitor, A, whom becomes a member/author for the account user abc, and also wishes to signup with xyz. A will need to register with abc, and then re-register with xyz, since there is not connection between the 2 users as they are using different databases? What would be the pros and cons to put the members under the default portal database, so that they only need 1 id to login and access, or leave them under the database of the separate accounts? Thanks.
jl