Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 转义单引号_Mysql - Fatal编程技术网

Mysql 转义单引号

Mysql 转义单引号,mysql,Mysql,我有一张这样的桌子 select * from myescape; +-----------+ | name | +-----------+ | shantanu' | | kumar's | +-----------+ 2 rows in set (0.00 sec) 我需要用“”替换单引号 我还需要对双引号和反斜杠进行转义。您可以使用 有用链接 准备好的陈述的要点是,你不必在陈述中包含内容。使用带有占位符的准备查询,然后执行。。。使用传入值而不必转义它们 不要试图逃避自

我有一张这样的桌子

select * from myescape;
+-----------+
| name      |
+-----------+
| shantanu' |
| kumar's   |
+-----------+
2 rows in set (0.00 sec)
我需要用“”替换单引号

我还需要对双引号和反斜杠进行转义。

您可以使用

有用链接


准备好的陈述的要点是,你不必在陈述中包含内容。使用带有占位符的
准备
查询,然后执行。。。使用
传入值而不必转义它们

不要试图逃避自己,因为你很可能会犯错误。根据您使用的编码,它可能不仅仅是反斜杠转义引号、反斜杠和null

UPDATE myescape SET name = REPLACE(name, "'", "\\'");
你可能想精确地思考一下为什么你可能想这样做(正如托马拉克所说)。即使在存储过程中,这些字段也应该是字符串,而不是命令。

尝试以下方法:

SELECT REPLACE( REPLACE( name , "'", "\\'" ) , '"', '\\"' )
FROM myescape

你忘了告诉我你为什么要这么做。在存储过程中,我使用的是prepare语句。单引号是在mysql数据中找到的单引号处完成的。列中都有单引号和双引号,因此我不能使用任何引号来完成准备好的语句。您是在应用程序中使用php还是什么?因为使用php要容易得多。双引号不能用它来处理。它添加了额外的单引号SELECT('Don't!')@山塔诺,你为什么认为双引号需要被逃避?
SELECT REPLACE( REPLACE( name , "'", "\\'" ) , '"', '\\"' )
FROM myescape