Nolongerused3921 Posted February 2, 2007 Share Posted February 2, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/36806-slashes-disappear-after-addinggetting-something-from-mysql/ Share on other sites More sharing options...
Jessica Posted February 2, 2007 Share Posted February 2, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/36806-slashes-disappear-after-addinggetting-something-from-mysql/#findComment-175591 Share on other sites More sharing options...
Nolongerused3921 Posted February 2, 2007 Author Share Posted February 2, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/36806-slashes-disappear-after-addinggetting-something-from-mysql/#findComment-175596 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.