Imagine that we have an e-shop. We need to store images connected with products somewhere on server. We already know, that it is better to store images in filesystem and keep the reference in DB.

The question is what is the best way to interconnect images in filesystem with product in DB:

I am thinking about:

  1. keep the reference to unique folder dynamically created for this product in DB (f.e. directly in products table)

  2. create new table in db (something like product_and_images) where we will keep information about product identification and image identification and table will serve for all products

Thanks for all of your answers and sorry for my terrible english :)

有帮助吗?

解决方案

It is always better to maintain separate table and use foreign key reference

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top