views:

1312

answers:

4

So I have a large 2d array that i serialize and base64_encode and throw into a database. On a different page I pull the array out and when I base64_decode the serialized array i can echo it out and it definitely looks valid.

However, if i try to unserialize(base64_decode($serializedArray)) It just throws the same error to the point of nearly crashing firefox.

The error is:

Warning: unserialize() [function.unserialize]: Node no longer exists in /var/www/dev/wc_paul/inc/analyzerTester.php on line 24

I would include the entire serialized array that I echo out but last time I tried that on this form it crashed my firefox.

Does anyone have any idea why this might be happening?

Thanks.

+4  A: 

Are you sure you're just serializing an array, and not an object (e.g. DOMNode?) Like resources, not all classes are going to be happy with being unserialized. As an example with the DOM (which your error suggests to me you're working with), every node has a reference to the parentNode, and if the parentNode doesn't exist at the moment a node is being unserialized, it's not able to recreate that reference and problems ensue.

I would suggest saving the dom tree as XML to the database and loading it back later.

Daniel Papasian
In fact, a quick Google of the error turns up several pages where SimpleXML is serialized and the unserialize turns up the error.
Michael Johnson
+3  A: 

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.

dirtside
That was my idea as well. Besides, base64 doesn't really help in making the data smaller. (Is this encoding really needed? Isn't it possible to store the data as it is right now?)
jan.vdbergh
A: 

What type of elements are in your array? serialize/unserialize does not work with built-in PHP objects, and that is usually the cause of that error.

Also, based on your comment this isn't your problem, but to save space in your database don't base64 encode the data, just escape it. i.e. for mysql use mysql_real_escape_string.

Gerald
A: 

Make sure you don't serialize resources, they can't be serialized.

[email protected]

michal kralik