views:

52

answers:

1

I have a listing of names, that I want to store in mysql as a serialized array (for caching purposes). Some names contain apostrophes, and for some reason won't un-serliaze properly. There is no output.

+2  A: 

Use mysql_real_escape_string on the serialized string prior to inserting into the database. You could handle storing serialized data bybase64_encodeing it prior to inserting it in the database, and base64_decodeing it upon retrieval, but with proper escaping that is unnecessary.

karim79
oh. Are you really base64'ing data to store it in the database?
Col. Shrapnel
@Col. Shrapnel - No. I've not done that (in PHP). But theoretically, it does allow you to sidestep many caveats involved in storage of serialized strings and just 'relax'. Also, I did say 'my favourite' and not 'the be it all, end all way would be to...'. But thank's for downvoting.
karim79
Yeah I understand. Working code at any cost. Leads you to accepted answer and more precious rep, no matter you didn't solve anything but just made a dirty patch.
Col. Shrapnel
+1 for mysql_real_escape_string. base_64_encode is unnecessary if you're properly escaping.
Frank Farmer
@Frank if you read the question, there is not insert problem but unserializing one.
Col. Shrapnel
Thank you for your attention to my humble person. But I prefer to discuss programming questions.
Col. Shrapnel
If you're inserting and selecting correctly, unserialization should work without issue. If unserializing is failing, then you're probably not storing/retrieving data correctly.
Frank Farmer