如何在 MySQL 中转义单引号

2021-11-20 00:00:00 string mysql quotes

如何在 MySQL 中插入由单引号或双引号组成的值.即

How do I insert a value in MySQL that consist of single or double quotes. i.e

This is Ashok's Pen.

单引号会产生问题.可能还有其他转义字符.

The single quote will create problems. There might be other escape characters.

如何正确插入数据?

推荐答案

简单地说:

SELECT 'This is Ashok's Pen.';

因此在字符串内部,将每个单引号替换为两个.

So inside the string, replace each single quote with two of them.

或者:

SELECT 'This is Ashok\'s Pen.'

逃脱它 =)

相关文章