开发者

MySQL Update Serialized Data

How to update serialized data in DB Table fie开发者_JAVA技巧ld?

I want to store serialized data to reduce count of queries but don't have idea how to update them.


You have to fetch the serialized data, unserialize() it, change it, serialize() it back again and update the table row in the database with the new serialized data.

This is too slow / troublesome, and it's the reason you shouldn't be storing serialized data in the DB.


In general, and certainly where you're wanting to store large amounts of data, Alix is right; try to store your data as rows in a table on the database.

As an example, here's someone asking for help in storing a huge slab of what looks like shopping cart data, which is exactly the kind of thing you need to avoid doing.

However, if you're dealing with small amounts of data, then serializing is appropriate, since simply reading a row to retrieve serialized data to then write it back probably isn't a huge resource burden.

As an example, I'm working on a hotel reservation system, whereby each client can add venues, which they can then associate with their different customers. For simplicity, I'm using serialized data instead of rows.

In this instance, I'm storing a series of client IDs into the row for the venue.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜