开发者

What is the best way to store a list of key values in one mysql column

I need to store data that can be variable, e.g. (data1='test1',data2='test2').

Is json the best way to do this ? or ther开发者_如何学Goe is a better way?

Creating a table to contain the value, can't be done since the keys are dynamic.


create a table where columns would be your keys and rows would contain values

And never use your database to store data like json. that's disgusting


I would do it in JSON, yes. Just be sure to have a column data size that's long enough to accomodate your JSON strings.

You might want to have a look at MongoDB and other non-structured databases one day though, they're the more elegant way to do that.


JSON is a format for storing transfering values into/within javascript.

MySQL is a relational database and you should structure your data accordingly - i.e. it should be normalised. From the information you've provided it is impossible to say whether the right relational model for your data would across multiple columns or across multiple rows.


You can use serialize() to store your array in a single column. Use unserialize() when fetching the data from your table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜