Kev*_*rke 1 security escaping go
我想逃避构成数据库查询一部分的值,但我不能使用参数化查询.
Go是否有相当于mysql_real_escape_string我可以用来逃避查询值的PHP ?
我想出了自己的解决方案来自己创建这个功能.
希望它对某人有用.
func MysqlRealEscapeString(value string) string {
replace := map[string]string{"\\":"\\\\", "'":`\'`, "\\0":"\\\\0", "\n":"\\n", "\r":"\\r", `"`:`\"`, "\x1a":"\\Z"}
for b, a := range replace {
value = strings.Replace(value, b, a, -1)
}
return value
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2496 次 |
| 最近记录: |