Question about Serializing some Contact Form data
I have a question about serialization and using with a MySQL DB.
i have contact form data being collected and have serialized using jQuery serialize() method.
I serialized partly as an excercise but also because someone here on this list recommended it,maybe i shouldn't serialize?!
The data is only 7 fields of text input, typical stuff, firstname, lastname, company, email etc.
Typically what happens to serialized data such as above? would it be put into a single cell?, or separated out into multiple columns?, why do it in the first place?, maybe i shouldn't serialize at all?
any advice would be very much appreciated.
The only reason (DB-wise) to serialize it is if you in fact want to store it all in one field (probably a TEXT field in MySQL). Normally I would only do this for data that might have a variable structure, such that you cannot say from instance to instance what "columns" need to be defined to hold it; and in doing so you are willing to give up any reasonable ability to search/sort that data via the database itself. Where I've mainly seen it used is for using a database to store PHP session data (instead of file system storage), whereby you can simply serialize the $_SESSION array and store the result in on text column (with other columns for session ID, timestamp, etc.).
In your example, however, it seems like you know what the data structure will be, which sounds like it should have a corresponding table in the DB with that structure, and thus no need to serialize it -- unless I'm missing something?
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
How to Ask Questions the Smart Way
(not affiliated with this site, but well worth reading)
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)