Malork Malork - 1 month ago 5
MySQL Question

Should I store product lists to users with arrays in MySQL?

Well, I have a big dilemma in my life about how to store product lists when I need to link that lists to an ID or something like that.

For this first example I'll gonna use the user cart.

I've always used this, even never liking it:

ID | PRODUCT
12 | Ring
12 | Necklace
12 | Bracelet


But lately I've been thinking about store arrays in MySQL. While it sounds like a good idea (in first view), by using arrays I'd only be able to manage the carts through PHP, by creating some kind of control panel or something.

Unfortunately, there is a con in it. Although the whole system take less space than the other way, I wouldn't be able to handle things through MySQL itself. Like, if someone make an order, I wouldn't be able to
SUM
the prices*quantity to get the order value.

What is the best way? Is there another way?

Answer

As soon as you store unstructured information in MySQL you lose most of the benefits of using a relational database and you only have an over-engineered file system (with, that's true, excellent multi-user capabilities). If you aren't familiar with SQL (which I suspect is the case) you'll initially think you're speeding development. But one day, if the shop hopefully grows, you'll realise that retrieving everything for further PHP postprocessing doesn't scale well.

While it can certainly make sense to outsource certain features (not the complete app) to a nosql database if you have a high concurrence site, if you use a relational database you'd better use it as it's meant to be used: with properly structured and normalised information.

Comments