Ninjakreborn Posted November 17, 2011 Share Posted November 17, 2011 I took an object, and saved it into a database serialized. $object_here = serialize($theobject); Then later on, I go and I get that data from a database, and try to unserialize it.. $objecthere = unserialize($row->theobject) And it throws the following error...any advice? Warning: unserialize() [function.unserialize]: Node no longer exists in /path/to/file on line 20 Link to comment https://forums.phpfreaks.com/topic/251310-cant-unserialize-objects/ Share on other sites More sharing options...
phporcaffeine Posted November 17, 2011 Share Posted November 17, 2011 1.) Make sure that the database field is large enough to hold the serialized array. Serialized data is very space-inefficient in PHP, and many DBs (like MySQL) will silently truncate field values that are too long. 2.) Make sure that you are not serializing a resource id / object (because they can't be serialized) 3.) When saving serialized data, don't try and do anything to it other than escaping ( mysql_real_escape_string() ) Link to comment https://forums.phpfreaks.com/topic/251310-cant-unserialize-objects/#findComment-1288926 Share on other sites More sharing options...
ManiacDan Posted November 17, 2011 Share Posted November 17, 2011 The manual says that's what happens when you try to serialize simpleXML objects. Since SimpleXML objects are meant to represent structured data, why not just...save the XML? Link to comment https://forums.phpfreaks.com/topic/251310-cant-unserialize-objects/#findComment-1288929 Share on other sites More sharing options...
Ninjakreborn Posted November 17, 2011 Author Share Posted November 17, 2011 I am taking an XML feed, and turning it into an array with $response = simplexml_load_string($results); Then I am turning the $response->actions which is an object, into a serialized string. Then saving it into a database table, as a varchar 225... it's not a large array though. Link to comment https://forums.phpfreaks.com/topic/251310-cant-unserialize-objects/#findComment-1288931 Share on other sites More sharing options...
Ninjakreborn Posted November 17, 2011 Author Share Posted November 17, 2011 It's "Long Text" so I am good there. I just deleted all the data. I am going to manually turn it into an actual array first, then serialize it. That should work. Thanks for the feedback. Link to comment https://forums.phpfreaks.com/topic/251310-cant-unserialize-objects/#findComment-1288938 Share on other sites More sharing options...
ManiacDan Posted November 17, 2011 Share Posted November 17, 2011 Is there a reason you're taking XML (a data storage/transmission format) and turning it into a serialized string (NOT a data storage format)? Link to comment https://forums.phpfreaks.com/topic/251310-cant-unserialize-objects/#findComment-1288947 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.