SQL语法错误。但是,它在phpmyadmin下工作正常

时间:2020-03-13 作者:Kt H

我有以下错误:

[You have an error in your SQL syntax; check the manual that corresponds 
to your MariaDB server version for the right syntax to use near \'\' at line 4]

SELECT COUNT(*) FROM wp_postmeta AS a, wp_postmeta AS b 
WHERE a.post_id = b.post_id AND (a.meta_key = \'customer_email\' 
AND a.meta_value LIKE \'%[email protected]%\') AND (b.meta_key = \'usage_count\' AND b.meta_value = \'0\'
但是,它在PHPMYADMIN正常工作

我不知道出了什么问题。

我的代码是

$rowcount = $wpdb->get_var("SELECT COUNT(*) 
FROM $wpdb->postmeta AS a, $wpdb->postmeta AS b WHERE a.post_id = b.post_id AND (a.meta_key = \'customer_email\' 
AND a.meta_value LIKE \'%[email protected]%\') AND (b.meta_key = \'usage_count\' AND b.meta_value = \'0\'");

echo $rowcount;
如何修复此问题?

1 个回复
最合适的回答,由SO网友:Asha 整理而成

)上一种情况下缺少支架。(即AND(b.meta\\u键=\'usage\\u count\'和b.meta\\u值=\'0\');)

 $rowcount = $wpdb->get_var("SELECT COUNT(*) 
FROM $wpdb->postmeta AS a, $wpdb->postmeta AS b WHERE a.post_id = b.post_id AND (a.meta_key = \'customer_email\' 
AND a.meta_value LIKE \'%[email protected]%\') AND (b.meta_key = \'usage_count\' AND b.meta_value = \'0\')");

echo $rowcount;

相关推荐

MySQLI_QUERY():MySQL服务器已离开以进行Curl请求

我创建了一个WordPress插件,激活后在jquery Datatable中显示结果。我们正在通过CURL Post获取结果。帖子URL是ASP。Net应用程序。该插件是为在帖子中添加我的短代码后遇到以下错误的客户创建的。客户端使用的是优雅主题的Divi(最新版本),WordPress 5.2.2运行在Apache/PHP 7.2.21上此错误仅显示在添加了快捷码的帖子页面上:警告:mysqli\\u query():MySQL服务器已消失在/homepages/10/d241347454/htdocs