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 #170677 is a reply to message #170651] Sun, 14 November 2010 19:08 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 11/13/2010 3:41 AM, Helmut Chang wrote:
> Am 13.11.2010 04:28, schrieb Jerry Stuckle:
>
>> mysql_real_escape_string() won't change backslashes.
>
> Of course it does. It's exactly, what this function is for:
>
> <http://www.php.net/manual/en/function.mysql-real-escape-string.php>
>
> | mysql_real_escape_string() calls MySQL's library function
> | mysql_real_escape_string, which prepends backslashes to the following
> | characters: \x00, \n, \r, \, ', " and \x1a.
>
>> It has no way to
>> know if, for instance, "\n" is a newline character or a backslash and an
>> n.
>
> Yes, it has. Because PHP has this ability:
>
> '\n' is a string, containing a backslash and an n
> "\n" is a string, containing only a newline character
>
> <?php
> $db = mysql_connect('localhost', ..., ...);
>
> $data = 'CÊ=3Fa=3F³Ýöâ8T\TBÆ';
> var_dump(mysql_real_escape_string($data, $db));
>
> $data = "Foo\nBar";
> var_dump(mysql_real_escape_string($data, $db));
>
> $data = 'Foo\nBar';
> var_dump(mysql_real_escape_string($data, $db));
> ?>
>
> Helmut
>

You're correct on the specific case of "\n" and I am incorrect. However,
please read more closely. It does NOT handle every other instance of a
backslash - it doesn't, for instance, handle \t or \b, both of which are
valid control characters. In fact, it only handles 5 specific cases.

--
==================
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 17:51:22 GMT 2024

Total time taken to generate the page: 0.04681 seconds