Re: store backslash in mysql database [message #170651 is a reply to message #170645] |
Sat, 13 November 2010 08:41 |
Helmut Chang
Messages: 22 Registered: September 2010
Karma:
|
Junior Member |
|
|
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
|
|
|