Anonymous Anonymous - 2 years ago 238
PHP Question

Add user registration and subscription to a PHP MySQL web app

I've been working on a web app for a few months now. It's a PHP and MySQL driven database app which relates objects between each other.

I'd like to add functionality so that someone could register to use it and set up a monthly subscription. When they log in the app would simply populate with data from their own database.

I've done some scouring online but I'm struggling to find a starting point for adding this sort of feature.

The app relies on half a dozen tables within a database. So I'm also not sure if creating an individual database per user is practical.

Answer Source

Creating a db per user is very rarely the way to go - it's complicated and has very few benefits with lots of drawbacks (eg maintaining multiple simultaneous Db connections as most libraries only connect to a single Db). What you really need to do is create a user table and then tag various records with a UserId.

When a user registers, create a new User record, then create their new entries in other tables all referencing that Id. (Actually, only the "root" of each relational object needs a UserId eg If you have Order and OrderItems only the Order table needs a UserId)

Without more detail, it's impossible to help further.

Incidentally, the only time you should consider db-per-user is if each user requires unique tables (in which case your app would have to be very complex to actually use the data) or if there are security concerns re: storing data together (more likely with multiple clients than multiple users).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download