如何在mysql语法中使用引号?

如何在mysql语法中使用引号?,mysql,Mysql,我在PHPMyadmin中尝试了以下内容: Update wp_1_posts SET post_content='<strong>Hello </strong> <a href="http://stackoverflow.com">stackoverflow</a> you think you're good at sql.\n then answer\n' WHERE post_ti<tle = 'stupid example

我在PHPMyadmin中尝试了以下内容:

Update wp_1_posts 
   SET post_content='<strong>Hello </strong> <a href="http://stackoverflow.com">stackoverflow</a> you think you're good at sql.\n then answer\n' 
 WHERE post_ti<tle = 'stupid example'

它说的是糟糕的语法。为什么?

你可以在你的帖子中看到。红色文本以“in you's”结尾。你需要避免引用。您只需在其前面添加\即可。您是。

您必须对单词中的单引号进行转义,才能使其成为您的语句。

对于MySQL,字符串中的单引号必须进行转义,并在其前面加上\号:

'this is a string with a \' quote inside of it'
作为参考,您可以查看MySQL手册的这一部分:

在您的情况下,您的查询应该如下所示:

Update wp_1_posts 
SET post_content='<strong>Hello </strong> <a href="http://stackoverflow.com">stackoverflow</a> you think you\'re good at sql.\n then answer\n' 
WHERE post_title = 'stupid example'

注意\n我在think you's good中添加了。

您必须在读取字符串中转义引号


如果发布错误的完整输出,也会有所帮助。很多时候,MySQL会给你一个更详细的错误,可以准确地告诉你错误在哪里。
Update wp_1_posts SET post_content='<strong>Hello </strong> <a href="http://stackoverflow.com">stackoverflow</a> you think you\'re good at sql.\n then answer\n' WHERE post_title = 'stupid example'