gpt4 book ai didi

php - mysql_real_escape_string() 坏了吗?

转载 作者:IT老高 更新时间:2023-10-29 00:09:32 24 4
gpt4 key购买 nike

有些人认为 mysql_real_escape_string() 有一些缺陷,即使正确使用也无法保护您的查询。
带来一些fossilized articles作为证明。

那么,问题来了:mysql[i]_real escape_string() 完全不能接受吗?
或者仍然可以使用这个函数来创建你自己的预处理语句?

请提供验证码。

最佳答案

来自 MySQL’s C API function mysql_real_escape_string description :

If you need to change the character set of the connection, you should use the mysql_set_character_set() function rather than executing a SET NAMES (or SET CHARACTER SET) statement. mysql_set_character_set() works like SET NAMES but also affects the character set used by mysql_real_escape_string(), which SET NAMES does not.

所以不要使用 SET NAMES/SET CHARACTER SET 而是使用 PHP’s mysql_set_charset更改编码,因为它与 MySQL 的 mysql_set_character_set 对应(参见 source code of /ext/mysql/php_mysql.c)。

关于php - mysql_real_escape_string() 坏了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5288953/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com