简体   繁体   中英

PHP/MYSQL How do you store a multidimensional array in a database - json or another table?

I am currently developing an application which requires the storage of a multidimensional array in a database. Currently I am taking the array which is 3 tiers deep and could be any size as it is populated with user-generated information, and using json_encode() to convert it into a string and enter it into the database.
The issue with this is that the single field is extremely large and difficult to read, to update the data I have to retrieve the data, decode it, update it, encode it and re-upload it. If the site did become used by many I am unaware of how this would scale.
I think the main alternative would be to create another table, with each row accessed by a unique id stored in the main table, but again I am unsure how well this would scale
Which is better? Any help much appreciated:)

If you are not sure how many tiers deep your array could be it's really hard to design the db schema.So best way to store is in a text field which you are doing already.

As for as scaling is concerned with proper indexing and partitioning you and scale you application however one field with large text value has nothing to do with scaling.

创建多个数据库表以及这些表之间的关系以将数据分组在一起可能会更容易维护,并使您能够基于列查询/过滤结果,而不必在PHP中检索,解码和迭代数据。

I think if you are not sure about how deep your array can be ,,,,than either you build a well constructed database that will be bit difficult so just do as you have planned. As I would suggest make use of functions as much as you can.

Function for encoding and function for decoding for json data (of any tiers) and use these functions and carry out your updates.

Using separate functions will obviously beautify your project and codes wont mess up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM