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 :(

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.