![]() |
Storing and retreiving serialized data that has single and double quotes - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Storing and retreiving serialized data that has single and double quotes (/showthread.php?tid=48879) |
Storing and retreiving serialized data that has single and double quotes - El Forum - 01-31-2012 [eluser]skunkbad[/eluser] Just wondering what is the best practice for preparing data for serialization, and then what do do when retreiving it from the database. I'm current using addslashes while looping through my array before serialization, and that allows me to properly store the serialized array, but when I look in the database using phpMyAdmin, the backslashes aren't there. When I retreive the data, I have to do a string replace for the single quotes to add slashes to them again. I think CI is stripping the slashes when the data is being inserted. Because I'm using a complex query for the insert, I'm using question marks as placeholders for the data in the query, and using $this->db->query(); When I retreive the data, if there is double quotes, the serialized data is basically corrupt. Any ideas? Storing and retreiving serialized data that has single and double quotes - El Forum - 01-31-2012 [eluser]vbsaltydog[/eluser] CodeIgniter is likely using mysql_real_escape_string() on any data before insertion. Can't you just use addslashes on the data after your retrieve it from the db? Storing and retreiving serialized data that has single and double quotes - El Forum - 01-31-2012 [eluser]CroNiX[/eluser] Take a look at their custom serialize/unserialize methods in the session class. I believe you might need to do something similar. Storing and retreiving serialized data that has single and double quotes - El Forum - 01-31-2012 [eluser]InsiteFX[/eluser] I copied the serialize and unserialize methods from the session class and use them for cookie data arrays. Storing and retreiving serialized data that has single and double quotes - El Forum - 02-01-2012 [eluser]skunkbad[/eluser] Hey guys, thanks for the tips. I'll check out the session class. |