Welcome Guest, Not a member yet? Register   Sign In
Storing and retreiving serialized data that has single and double quotes
#1

[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?
#2

[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?
#3

[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.
#4

[eluser]InsiteFX[/eluser]
I copied the serialize and unserialize methods from the session class
and use them for cookie data arrays.
#5

[eluser]skunkbad[/eluser]
Hey guys, thanks for the tips. I'll check out the session class.




Theme © iAndrew 2016 - Forum software by © MyBB