Shopping Cart, Session or DB? [closed] Shopping Cart, Session or DB? [closed] mysql mysql

Shopping Cart, Session or DB? [closed]


You must know the criticality of the data. If you think that the data in your shopping cart is not critical and not needed for multiple sessions that you can just do it with sessions and save some writes to the DB.

Even if you do need a DB you can save some writes and use client side for temp storage and finally move it to your DB with some kind of a syncing mechanism.

But if your data is highly critical and it is mandatory that it persists in multiple sessions then DB would be an ideal choice as it would give you more power over the access to the data and also it will ease the implementation.


Session or DB is not exclusive choice - session can be stored in database as well. In some way you have to retrieve the cart for the user. In all cases you will have session for this. The question is if the cart should be persisted between sessions (for registered users). In that case you should not couple cart with the session. Things gets complicated if you want to save the cart for registered users, allow unregistered to have cart as well, and merge the session cart and the saved cart in case user logins.

So to answer your question, you should just clear your requirements.What means 'shopping cart under different stores'?Will be cart saved between logins (for example user comes back 1 week later)?

As for the security, it's usually preferred to save session in the database, as you can have additional protection who have access to the data, especially on a shared hosting.


With a DataBase implementation you have granular control and better persistence.

Use Session to know the loginned user between pages, but DataBase to store critical data.