我应该在db-PHP和Mysql中为产品创建2个表吗?

我应该在db-PHP和Mysql中为产品创建2个表吗?

问题描述:

I've got some question(s) How many tables should i create for my products ?

2???=products & products pics???

if yes then my mysql tables will be like that ? 1.products= p_id, p_name, p_descr, p_pieces, p_categ, p_subcateg(??) &

2.products_pics= pp_id, product_id, thumb, image, type (???)

Well im a little bit confused cause i think its not so necessary to use products_pics into the db anymore .

My product entries will be around 3.000 for the beginning . Can someone tell me what im going to write-do ??? Thank you very much !

You should make 3 tables

  • products
  • images
  • products_images

In table products you have id_prod (primary key), name_prod, and other.

In table images you have id_img (primary key), name_img or img_src.

In table products_images you link images with products, and structure should be like id (primary), id_prod, id_img.

This way you will not have a duplicate content in tables.

If you only have images / documents pertaining to products only, and you want to store them in your database, you can store the image as blob/longblob directly inside the products table as p_image for example. But when you want to retrieve it you will get the binary data, so you should write it to a file or convert it to view it as image under browser.

And if you have multiple images for the same product, you should create another table and use p_id as foreign key.

However, it is not advisable to store images in the database, for more information please refer to : Storing Images in DB - Yea or Nay?