PHP mysql_real_escape_string() and % character

心不动则不痛 提交于 2019-12-10 17:48:39

问题


What does mysql_real_escape_string() do with the % (percent) character and how much of a security risk does it represent (and how to fix it)?


回答1:


From the mysql_real_escape_string() documentation:

Note: mysql_real_escape_string() does not escape % and _. These are wildcards in MySQL if combined with LIKE, GRANT, or REVOKE.

As far as security, unless you are running a LIKE, GRANT, or REVOKE, it's a non-issue. LIKE is probably the only real concern. It's up to you how you would want to escape it in these situations.

A quick example:

"... LIKE '%" . mysql_real_escape_string($string) . "%' ..."



回答2:


It does not do nothing with % character. Why didn't you try it?




回答3:


Taken from:

http://php.net/manual/en/function.mysql-real-escape-string.php

Note: mysql_real_escape_string() does not escape % and _. These are wildcards in MySQL if combined with LIKE, GRANT, or REVOKE.



来源:https://stackoverflow.com/questions/6473823/php-mysql-real-escape-string-and-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!