为什么mysqli_real_escape_string将连接对象作为第一个参数 [英] Why mysqli_real_escape_string have a connection object as a first parameter

查看:40
本文介绍了为什么mysqli_real_escape_string将连接对象作为第一个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我长时间在PHP中使用MYSQLI函数. 我总是问我同样的事情: 为什么功能mysqli_real_escape_string需要第一个参数中的连接?没道理!这只是引用引号的功能.

I'm using MYSQLI functions in PHP for a long time. And I always ask me the same thing: Why the funcion mysqli_real_escape_string needs the connection in the first parameter? Doesn't make sense! It's just a funcion to scape quotes.

你知道为什么吗?

推荐答案

mysqli_real_escape_string必须知道连接的字符集,以便它可以正确地转义特殊字符.如果使用多字节集,则mysqli必须知道.否则,可以进行 sql注入.有关更多详细信息,请参见此答案.

mysqli_real_escape_string must be aware of the character set of the connection so that it can escapes special characters properly. If you use a multi-byte set then mysqli must know. Otherwise a sql injection is possibile. See this answer for more detail.

但是,请不要使用它!使用准备的语句

However, don't use it! Use Prepared Statements!

这篇关于为什么mysqli_real_escape_string将连接对象作为第一个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆