Best way to store an array in MySQL database?

后端 未结 3 1714
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 23:52

Part of my app includes volume automation for songs.

The volume automation is described in the following format:

[[0,50],[20,62],[48,92]] 

3条回答
  •  梦谈多话
    2020-12-31 00:33

    Definitely not a text field, but a varchar -- perhaps. I wouldn't recommend parsing the results and storing them in individual columns unless you want to take advantage of that data in database sense -- statistics etc.

    If you never see yourself asking "What is the average volume that users use?" then don't bother parsing it.

    To figure out how to store this data ask yourself "How will i use it later?" If you will obtain the array and need to utilize it with PHP you can use serialize function. If you will use the values in JavaScript then JSON encoding will probably be best for you (plus many languages know how to decode it)

    Good luck!

提交回复
热议问题