开发者

how to use quote in mysql syntax?

开发者 https://www.devze.com 2023-01-07 12:32 出处:网络
I try this in PHPMyadmin: Update wp_1_posts SET post_content=\'<strong>Hello </strong> <a href=开发者_开发问答\"http://stackoverflow.com\">stackoverflow</a> you think you\'re

I try this in 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'

and it says bad syntax. Why ?


With MySQL, single-quotes inside a string have to be escaped, putting a \ before them :

'this is a string with a \' quote inside of it'

As a reference, you can take a look to this section of the MySQL manual :

  • 8.1.1. Strings


In your case, your query should look like this :

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'

Note the \ I've added in think you\'re good.


You can see it in your post. The red text ends at the ' in you're. You need to escape the quote. You can simply add \ before it. you\'re.


You have to escape the single quote in the word you're to make it you\'re in your statement.


You have to escape quotes inside string (read the manual).

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'
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号