I know what and how PHP serialize works. But I am wondering what type of data/structure should be serialized when stored in a database.
I am building a sort of address book system in PHP with fields like this:
Name, Firstname, Street, City, Zip, etc.
I can serialize my data to store it in my database or have different fields for each item to store.
Any tips, suggestion, thoughts?
If I understand correctly, your indecision is on whether to serialize an object or an array containing all the fields and store the result in the database or whether to store each field individually in a table column.
In the absence of extraordinary circumstances, I’d advise you to do the latter. It will allow you to search, sort, cross reference etc. much more efficiently in the database.
Serialization is more common when transmitting data or saving complex object graphs in order to save a part of the script state, not so much to store data in the database.