mysql - SQL syntax error. However, it works normally at phpmyadmin

I have this error :[You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server vers

I have this error :

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

However, it works normally at PHPMYADMIN

I don't know what went wrong.

my code is

$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;

How to fix this ?

I have this error :

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

However, it works normally at PHPMYADMIN

I don't know what went wrong.

my code is

$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;

How to fix this ?

Share Improve this question asked Mar 13, 2020 at 8:29 Kt HKt H 152 silver badges6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

) bracket missing in last condition. (i.e AND (b.meta_key = 'usage_count' AND b.meta_value = '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;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744672713a4587141.html

相关推荐

  • mysql - SQL syntax error. However, it works normally at phpmyadmin

    I have this error :[You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server vers

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信