Mysql查询显示phpmyadmin中的错误

时间:2015-10-14 04:22:09

标签: mysql

我正在尝试查找具有短代码的页面ID。这是我试图在mysql SELECT ID FROM wp_posts WHERE post_type = "page" AND post_status="publish" AND post_content LIKE "%[registration id="17"]%"

中运行的查询
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '17"]%"

但显示以下错误

{{1}}

LIMIT 0,25'在第1行

提前致谢。

2 个答案:

答案 0 :(得分:3)

你的sql有问题

SELECT ID FROM wp_posts WHERE post_type = "page" AND 
post_status="publish" AND post_content LIKE "%[registration id="17"]%"
                                                               ^^^^^^

在where where part中使用'代替"

SELECT ID FROM wp_posts WHERE post_type = "page" AND 
post_status="publish" AND post_content LIKE "%[registration id='17']%"

如果你真的想要匹配 registration id="17",请尝试逃避"

SELECT ID FROM wp_posts WHERE post_type = "page" AND 
post_status="publish" AND post_content LIKE "%[registration id=\"17\"]%"

OR

SELECT ID FROM wp_posts WHERE post_type = "page" AND 
post_status="publish" AND post_content LIKE '%[registration id="17"]%'

答案 1 :(得分:0)

试试这个

SELECT ID FROM wp_posts WHERE post_type = "page" AND post_status="publish" AND post_content LIKE "%[registration id='17']%";

 SELECT ID FROM wp_posts WHERE post_type = "page" AND post_status="publish" AND post_content LIKE '%[registration id="17"]%';