Hello guys, I need a little info. I'm trying to save data in serialized form. I'm getting two different results. Can anyone please tell me whats the 'technical' difference between both results?
Explain to us why you are saving the data serialized? and what should the data contain? with this only the length is differend!
Please don't use serialize for this purpose, use the database abilities for it! Create a table for followers with 2 (or more) fields (user_id, follow_userid) that's way better.. That way you always have correct results...
A good comment on PHP seralize documentation explains what you need: Anatomy of a serialize()'ed value: String s:size:value; Integer i:value; Boolean b:value; (does not store "true" or "false", does store '1' or '0') Null N; Array a:size:{key definition;value definition;(repeated per element)} Object O:strlen(object name):eek:bject name:eek:bject size:{s:strlen(property name):property name:property definition;(repeated per property)} String values are always in double quotes Array keys are always integers or strings "null => 'value'" equates to 's:0:"";s:5:"value";', "true => 'value'" equates to 'i:1;s:5:"value";', "false => 'value'" equates to 'i:0;s:5:"value";', "array(whatever the contents) => 'value'" equates to an "illegal offset type" warning because you can't use an array as a key; however, if you use a variable containing an array as a key, it will equate to 's:5:"Array";s:5:"value";', and attempting to use an object as a key will result in the same behavior as using an array will. Code (markup): Source
Serializing the data is _a_ solution, but it's not the _right_ solution. It rarely ever is. The better solution (perhaps the right one), is to create separate tables, preferably with foreign keys as well, and put them in there - as @EricBruggema said in the post above. This is the whole point of relational databases - you have a table with a unique identifier, which you then can use to connect other data and create new relationships - for instance by adding a user_followers and user_following table (strictly speaking, you only really need one, which is user_relationship - where you have user_id, connected_user_id, following, follower - that's basically all you need. Then you create a new entry in that table every time there's a new connection between user_id and connected_user_id - and update it if it changes.
In the first table where you have s:1, you have an integer and a string, while in the second table you have 2 integer values Make sure you will insert your data like this: $data = array (0,3) instead of $data = array( 0, '3'); so that php will not attempt to index that as a string.
Hi guys, sorry for late follow up. I've realized that serialization is not convenient. I was thinking to take serialization to json for iphone app. Now I'm using simple arrays. Thanks for clarification.