开发者

MySQL update/insert strips backslashes for unicode entries

I'm trying to insert/update a SQL field with JSON data that encodes unicode as \u, but it's stripping it out:

"Sauteéd -> ["Saute\u00e9d"]

However, it's being saved in the开发者_运维百科 database like this:

["Sauteu00e9d"]

I've tried countless preg_replace and str_replace methods, but none of them work. Is there something I can do about this - it's driving me mad.

Thanks!


Use mysql_real_escape_string if you aren't.


My guess is that you use PHP

In that case you should use mysql_real_escape string instead of preg replace. It's easier and much better against SQL injections.


mysql_real_escape_string is obviously now deprecated so here is how you would do it in modern PHP:

$value = $mysql_conn->real_escape_string("Saute\u00e9d");
$query = "update so_and_so set param = '$value' where var1 = 'somevalue'";
...
...

or however you happen to run your queries...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜