FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » store backslash in mysql database
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: store backslash in mysql database [message #170676 is a reply to message #170674] Sun, 14 November 2010 19:05 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 11/14/2010 1:47 PM, Magno wrote:
> On 11/13/2010 12:28 AM, Jerry Stuckle wrote:
>> On 11/12/2010 9:13 PM, Magno wrote:
>>> On 11/12/2010 07:03 PM, Peter wrote:
>>>> Let me apologise in advance as I'm unsure if this can be resolved with
>>>> php or I need to post to a SQL group.
>>>>
>>>> Anyway, I have some data that is encrypted before being stored, but I
>>>> noticed that sometimes the retrieved data, when decrypted, didn't match
>>>> the original data.
>>>>
>>>> What I discovered was that the encryption routine sometimes created the
>>>> backslash character as part of the encryption string. Something like:
>>>>
>>>> CÊ=3Fa=3F³Ýöâ8T\TBÆ
>>>>
>>>> However, when this was stored in the database, the backslash became
>>>> removed leaving:
>>>>
>>>> CÊ=3Fa=3F³Ýöâ8TTBÆ
>>>>
>>>> I thought, if I just add:
>>>>
>>>> $string = str_replace("\","\\",$string);
>>>>
>>>> that would resolve the problem. Thinking that an escaped backslash
>>>> would
>>>> allow the single backslash char to be stored.
>>>>
>>>> However, that appears to be syntatically incorrect with php.
>>>>
>>>> So is there any other way to force a backslash into the database, by
>>>> creating an escaped backslash, or am I going completely wrong and it
>>>> wouldn't have worked anyway and I need to deal with this issue on a
>>>> purely SQL basis.
>>>>
>>>
>>> Are you using MySQL? Then try mysql_real_escape_string();, that one will
>>> do the filtering to allow anything inside.
>>>
>>> You should consider also using PDO.
>>
>> mysql_real_escape_string() won't change backslashes. It has no way to
>> know if, for instance, "\n" is a newline character or a backslash and an
>> n. mysql_real_escape_string() is for single quotes (SQL string start/end
>> character) and the like, depending on the charset.
>>
>
> LOL, I was expecting that answer from you or Thomas p...
> well, Helmut already replied to you.

That is correct. And if you read the documentation carefully, you can
see that while I was wrong on the specific instance, I was correct in
the general sense.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: website url as input how to create and save image on server in php?
Next Topic: Cannot write utf8 data into a utf8 column
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 01:25:59 GMT 2024

Total time taken to generate the page: 0.04254 seconds