Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我是否正确使用mysqli\u real\u escape\u字符串?_Php_Mysqli - Fatal编程技术网

Php 我是否正确使用mysqli\u real\u escape\u字符串?

Php 我是否正确使用mysqli\u real\u escape\u字符串?,php,mysqli,Php,Mysqli,我正在使用mysqli\u real\u escape\u string的OOP方法对字符串进行转义。我将输入保存到会话变量中,以确保它正确转义。它似乎转义正确,但当我检查输入数据库的内容时,我没有看到单引号和双引号前面的斜杠 因此,我在浏览器中回显: Array ( [formContent] => I\'m always here! ) 但在数据库中我看到: I'm always here! 这是否意味着我的代码有问题?没有,这是正常的mysqli\u real\u esc

我正在使用
mysqli\u real\u escape\u string
的OOP方法对字符串进行转义。我将输入保存到会话变量中,以确保它正确转义。它似乎转义正确,但当我检查输入数据库的内容时,我没有看到单引号和双引号前面的斜杠

因此,我在浏览器中回显:

Array
(
    [formContent] => I\'m always here!
)
但在数据库中我看到:

I'm always here!

这是否意味着我的代码有问题?

没有,这是正常的
mysqli\u real\u escape\u string
自动为您转义单引号

当你有了绳子

I'm always here!
mysqli\u real\u escape\u string
将其处理为

I\'m always here!
因此,它将保存在数据库中。这就是它的工作原理

-转义字符串中的特殊字符以用于SQL语句,同时考虑连接的当前字符集

它在单引号中转义了什么(从某种级别的sql注入中保存)

mysqli\u real\u escape\u string
将其处理为

hello \'world

您可以使用
stripslashes
删除
\

查询是否中断?如果不是,那就意味着逃跑是有效的。顺便说一句,斜杠是在查询执行时“内部”添加的,而不是在数据本身上,因此您不会在数据库中看到它们。旁注:因为您使用的是mysqlI,所以应该研究查询参数化,而不是手动转义输入。这就是它的工作原理。代码中没有错误。@DamienPirsy没有,查询没有中断。否则,我的内容将正确输入。只是想确定我做得对。谢谢你的建议。@heyjohnmurray这是一个重复的问题:),我知道查询没有中断。如果你发现自己需要使用
stripslashes
,就会出现可怕的问题。
hello \'world