Jump to content

Slashes disappear after adding/getting something from mysql


Nolongerused3921

Recommended Posts

For some reason my slashes seem to disappear from my serialized array upon adding it into the database... According to the string count, its 133 characters long when I add it into the db, but when I take it out - its 128 characters long... And considering theres 5 's, and the slashes that were previously added prior to committing to the database, I'd say these slashes have been automatically taken out when I try to get the data...

 

So whats going on here? WHY are my slashes that I add with mysql_real_escape_string() being removed automatically? And how do I stop it... Because unless the array count is exact, you can't unserialize an array :(

The \ before a ' escapes the '. If you really want to insert the string exactly as  \'  you need to send \\\' into the database.

One \ to escape the first \ and another \ to escape the '.

 

Although the text in your strings shouldn't have those escaping slashes until it's about to go in the DB, not just as regular data.

So in otherwords mysql doesn't take \' as a literal string but rather as an escaped string, and I need to add an EXTRA layer of addslashes()?...

How exactly am I going to do this... ? I can't addslashes() to a serialized string, since it'll mess with the formatting... And I can't just addslashes() to the array entries, and str_replace() wouldn't account for everything....

 

Is there some function in php that already handles this kind of stuff for serialization + mysql?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.