mysql - 如何在MySql中转义撇号(单引号)?

标签 mysql escaping

MySQL documentation说它应该是\'。然而,scite 和 mysql 都显示 '' 有效。我看到了,它有效。我该怎么办?

最佳答案

您引用的 MySQL 文档实际上比您提到的要多一些。它还说,

A “'” inside a string quoted with “'” may be written as “''”.

(此外,您链接到 MySQL 5.0 version of Table 8.1. Special Character Escape Sequences ,当前版本是 5.6 — 但当前的 Table 8.1. Special Character Escape Sequences 看起来非常相似。)

我认为Postgres note on the backslash_quote (string) parameter内容丰富:

This controls whether a quote mark can be represented by \' in a string literal. The preferred, SQL-standard way to represent a quote mark is by doubling it ('') but PostgreSQL has historically also accepted \'. However, use of \' creates security risks...

这对我来说,使用双单引号字符是比使用反斜杠转义单引号更好的整体和长期选择。

现在,如果您还想在等式中添加语言选择、​​SQL 数据库选择及其非标准怪癖以及查询框架选择,那么您最终可能会得到不同的选择。您没有提供太多有关您的限制的信息。

关于mysql - 如何在MySql中转义撇号(单引号)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54975177/

相关文章:

php - 尝试将数据插入数据库时​​出错。简单的形式

c# - 在 MYSQL 中插入 TIMESTAMP 数据?错误 "MYSQL version for the right syntax to use near etc"

mysql - 将 mySQL 表中的列值替换为第二个表中的值

powershell - POST请求变量powershell

python - 为什么引号的类型会改变字符串的值? - Python

java - 在java中将国际字符串转换为\u代码

java - java解析xml时出现异常

javascript - 我需要同时使用 PHP 和 Javascript 进行计算吗?

mysql - 在 JEE6 环境下访问数据库的最佳方式是什么?

java - 使用 JdbcTemplate 时转义单引号