Tuesday, 15 June 2010

php - Is it bad design to use json_encode data instead of creating new table? -


I have an order and some products related to each order. I want to save name, price and short descriptions for each product.

I know that the general approach is to create two tables, orders and products , but what if I specifically query the products Do not need to? Is there to fix json_encode products on object objects with PHP and save it as a column on order table in mysql

If the data is constantly structured (it seems like this), you should create a table.

JSON or other serialized format is good for data which is incompatible.

It is convenient to store product information in order (which is part of the NSQL database appeal), but as long as the data structure varies between products, you can create data in a relational manner It's best to follow the standard.


Use case where JSON will be helpful:

Assume that you were tracking an event stream but there was information about events before checkout You may want to archive the data that is not stored continuously, you can see the order table

  {type: "page_visited", data: {url: at  order_analytics The following can be stored in the  column. "Product_id: 4, product_name:" example product "}}, {type:" removed_from_cart ", data: {product_id}," / example / 1 ", title:" example page "}}, {type:" added_tocart " : 4, product_name: "example product"}}  

No comments:

Post a Comment