sql.go 442 B

12345678910111213141516171819
  1. package common
  2. import "strings"
  3. // SqlStrReplaceSingleQuotes 防止sql注入 单引号
  4. func SqlStrReplaceSingleQuotes(str string) string {
  5. if strings.Contains(str, "'") {
  6. str = strings.Replace(str, "'", "\\'", -1)
  7. }
  8. return str
  9. }
  10. // SqlStrReplaceDoubleQuotes 防止sql注入 双引号
  11. func SqlStrReplaceDoubleQuotes(str string) string {
  12. if strings.Contains(str, "\"") {
  13. str = strings.Replace(str, "\"", "\\\"", -1)
  14. }
  15. return str
  16. }