mysql_real_escape_string 将数据与反斜杠一起存储在数据库中

发布于 2024-09-01 16:51:52 字数 210 浏览 11 评论 0原文

当我在未转义的字符串上使用 mysql_real_escape_string 时,数据库中的数据存储时带有反斜杠,这是不应该发生的。

我关闭了 magic_quotes_gpc ,不知道为什么会发生这种情况。有什么想法吗?

mysql数据库有什么设置需要修改吗?

我没有在代码中的任何地方使用addslashes。 PHP 语言。

请帮忙。

When i am using mysql_real_escape_string on my unescaped strings the data in the database is storing with the backslashes which should not happen.

I have magic_quotes_gpc OFF not sure why this is happening. Any idea ?

Is there any setting in the mysql database which needs to be modified.

I am not using addslashes any where in the code. PHP language.

Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

惯饮孤独 2024-09-08 16:51:52

magic_quotes 有多种变体,所有这些变体都非常具有侵入性并且无法被覆盖。我认为 DBMS 不太可能完成额外的转义。

您在应用 mysql_real_escape_string() 之前检查过数据是什么样子吗?我敢打赌它已经以某种方式转义了。

C.

There are several variants of magic_quotes all of which are very invasive and cannot be overridden. I think its unlikely that that extra escaping is being done by the DBMS.

Have you checked what the data looks like before applying the mysql_real_escape_string() - I would bet its already escaped somehow.

C.

酒中人 2024-09-08 16:51:52

答案很简单。
mysql数据库中没有需要修改的设置。
这是您的代码/设置。

要么您启用了 magic_quotes_gpc 并且需要对其进行双重检查,或者您的某些代码进行了另一次削减。

the answer is simple.
There are no setting in the mysql database which needs to be modified.
It is your code/settings.

Either you have magic_quotes_gpc on and it needs to be double-checked, or some of your code does another slashing.

甜点 2024-09-08 16:51:52

stripslashes() 是当 PHP
指令 magic_quotes_gpc 已启用
(默认情况下处于打开状态),而您没有
将此数据插入到某个位置(例如
作为数据库)需要转义。
例如,如果您只是
直接从 HTML 输出数据
表格。

<?php
$str = "Is your name O\'reilly?";

// Outputs: Is your name O'reilly?
echo stripslashes($str);
?>

让我们知道当您使用 stripslashes 时,您的输入会变成什么。它是否达到所需的格式。这是为了检查您的输入是否有问题。

既然您已经告诉过,如果不应用 mysql_real_escape_string,您的数据将在没有任何 blackSlashes 的情况下存储...并且在应用它之后,您会得到 blackslash...我个人觉得仔细检查您的代码是否在某个地方应用了addslashes。

有些问题......

  1. 这种情况只发生在当前函数中吗?
  2. 检查你的 magic_quotes_gpc 是否打开或关闭。
  3. 您可以发布导致此问题的该功能的一部分吗?

stripslashes() is when the PHP
directive magic_quotes_gpc is on
(it's on by default), and you aren't
inserting this data into a place (such
as a database) that requires escaping.
For example, if you're simply
outputting data straight from an HTML
form.

<?php
$str = "Is your name O\'reilly?";

// Outputs: Is your name O'reilly?
echo stripslashes($str);
?>

Let us know when you use stripslashes, what does your input turn into. Does it get into required format. This is to check whether there is something going wrong with your input coming.

Since you have told that without applying mysql_real_escape_string your data gets stored without any blackSlashes... and after applying it you get blackslash... i personally feel double check your code whether you are applying addslashes some where.

Some questions...

  1. Does this happen only in this current function.
  2. Check your magic_quotes_gpc is on or off.
  3. Can you post a part of that function which is causing this problem.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文