Reputation: 1707
Currently I have a site with about 600 active members. I need to keep an "history" for each one, each week.
So every week I store 11 rows for each user, so that the table already has more than 30,000 rows.
I was thinking on serialize an php array with these 11 records and save them in one single row, to speed up the search and save space.
Do not know if it is good practice or not, I saw for example that Wordpress use this method.
Upvotes: 1
Views: 2068
Reputation: 297
The difficulty with storing serialized data is when an odd event happens and an arbitrary data pull is necessary. You'll need a php script/application that can handle that one off piece of data.
JSON encoded strings are much easier to deal with as you can actually decode it in a javascript prompt on your browser.
Upvotes: 0
Reputation: 562573
It's fine to store serialized data in a database, but you lose the ability to use SQL logic to do anything with individual records or fields of that serialized data.
Basically it becomes a "black box" or in other words an irreducible blob of data that SQL has no ability to work with, except to return the whole blob to the application. I.e. any read reads the whole blob, and any update would have to replace the whole blob.
Not that is is necessarily a bad thing -- it depends how you use that data. If it's normal for your app to read or write the whole blob every time it accesses it, and you never need to reference individual fields of it in SQL expressions, then you might as well serialize the data.
Upvotes: 2