简体   繁体   English

PHP mysqli_real_escape_string问题

[英]PHP mysqli_real_escape_string problems

I have several post variables that I run through the following: 我有几个post变量,我通过以下方式运行:

$input_name =  mysqli_real_escape_string($dbc, trim($_POST['input_name']));

I have run several tests where I echo $input_name and other like variables before the insert query executes. 我已经运行了几个测试,我在插入查询执行之前回显$ input_name和其他类似的变量。 The echo indicates that they are indeed getting escaped as they should. 回声表明他们确实正在逃避它们应该。

However, when I login to phpmyadmin to look at my entries in the DB, I see that characters that should be escaped are not. 但是,当我登录phpmyadmin查看数据库中的条目时,我发现应该转义的字符不是。 Do I have a problem here? 我这里有问题吗? Is something happening between my variable declaration and the query that I am not aware of? 在我的变量声明和我不知道的查询之间发生了什么?

Are there php or server settings that could be influencing this? 有没有可能影响这个的PHP或服务器设置?

note: I realize PDO is the way to go, I am just not there at this particular moment. 注意:我意识到PDO是要走的路,我不是在这个特定的时刻。

The *_real_escape_string functions in PHP are only there to prevent SQL injection therefor it will only change " to \\" and ' to \\' so that the following query: PHP中的* _real_escape_string函数仅用于防止SQL注入,因此它只会更改为“to”和“to”以便以下查询:

SELECT * FROM users WHERE pass = '' OR '1'='1 --

Will become: 会变成:

SELECT * FROM users WHERE pass = '\' OR \'1\'=\'1 --

So that the injected value won't work. 这样注入的值就不起作用了。

The echo indicates that they are indeed getting escaped as they should. 回声表明他们确实正在逃避它们应该。

This indicates that your characters are escaped. 这表示您的角色已转义。

when I login to phpmyadmin to look at my entries in the DB, I see that characters that should be escaped are not 当我登录phpmyadmin查看数据库中的条目时,我发现应该转义的字符不是

Now as you are escaping means that you want to those characters as it is rather than PHP or you database taking them internally as delimiters. 现在,因为你正在逃避意味着你想要那些字符而不是PHP或你的数据库将它们作为分隔符在内部。

Like if you want ' in your input as it is, so your are escaping it. 如果你想要像'在你的输入,因为它是让你在逃避它。 So now when database(mysql) sees it that is is escaped so it won't considered it as a single quote that is used for string literals in MySQL. 所以现在当数据库(mysql)看到它被转义时,它不会被视为用于MySQL中的字符串文字的single quote

If you don't escape it then MySQL will consider all the part between two ' as string literals. 如果你没有逃避它,那么MySQL将把两个'之间的所有部分视为字符串文字。

So everything is fine, don't worry about it. 所以一切都很好,不要担心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM