I am working on a module and it just makes things a lot easier to place data into a serialized field. I have several fields that are related and I really like putting them into a keyed array, and then serializing them, and then putting them into my database in one field.

The problem is, that serialized data contains some info, I need to query. Is using wild cards like I addressed in this post the ONLY way to do this..

http://drupal.org/node/732730

Or, is there some other, better way. Perhapse, there is a better way to store related information? Maybe I should use several database tables and then use joins?

Is serialize() taboo? It sure seems like an easy way to do what I need to do.

Thanks!

Comments

mitchmac’s picture

Serialization isn't taboo generally, but in this case I would avoid it or at least modify the way you are doing things. Your database queries on the serialized data will not perform nearly as well or allow for future data relationships compared to if you create some sort of schema to represent at least the data elements you want to query against.

If you only have a few fields you want to query on and a slight duplication of data doesn't bother you, you could store the serialized data and the query related data at the same time. Index and optimize your queries on the "search" data and build your result arrays with the serialized data.

jaypan’s picture

If you need to query it, then you shouldn't store it as serialized data.

Contact me to contract me for D7 -> D10/11 migrations.
Or anything really. I'm friendly, and open to work or conversation.