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 'ERROR: SELECT COUNT(DISTINCT p.productID) FROM ?#PRODUCTS_TABLE p where catego' at line 1 SQL query : ERROR: SELECT COUNT(DISTINCT p.productID) FROM ?#PRODUCTS_TABLE p where categoryID>1 and enabled=1 and ( LOWER(name) LIKE '%eiUNKNOWN_PLACEHOLDER_ion%' OR LOWER(product_code) LIKE '%eiUNKNOWN_PLACEHOLDER_ion%' OR LOWER(mas_id) LIKE '%eiUNKNOWN_PLACEHOLDER_ion%' OR LOWER(nametype) LIKE '%eiUNKNOWN_PLACEHOLDER_ion%' OR LOWER(comp) LIKE '%eiUNKNOWN_PLACEHOLDER_ion%' OR LOWER(contry) LIKE '%eiUNKNOWN_PLACEHOLDER_ion%' OR LOWER(productID) LIKE '%eiUNKNOWN_PLACEHOLDER_ion%' ) AND ( LOWER(name) LIKE '%6681%' OR LOWER(product_code) LIKE '%6681%' OR LOWER(mas_id) LIKE '%6681%' OR LOWER(nametype) LIKE '%6681%' OR LOWER(comp) LIKE '%6681%' OR LOWER(contry) LIKE '%6681%' OR LOWER(productID) LIKE '%6681%' ) AND ( LOWER(name) LIKE '%or%' OR LOWER(product_code) LIKE '%or%' OR LOWER(mas_id) LIKE '%or%' OR LOWER(nametype) LIKE '%or%' OR LOWER(comp) LIKE '%or%' OR LOWER(contry) LIKE '%or%' OR LOWER(productID) LIKE '%or%' ) AND ( LOWER(name) LIKE '%1=\\\\\\\\\\\\\\''0=a%' OR LOWER(product_code) LIKE '%1=\\\\\\\\\\\\\\''0=a%' OR LOWER(mas_id) LIKE '%1=\\\\\\\\\\\\\\''0=a%' OR LOWER(nametype) LIKE '%1=\\\\\\\\\\\\\\''0=a%' OR LOWER(comp) LIKE '%1=\\\\\\\\\\\\\\''0=a%' OR LOWER(contry) LIKE '%1=\\\\\\\\\\\\\\''0=a%' OR LOWER(productID) LIKE '%1=\\\\\\\\\\\\\\''0=a%' ) AND ( LOWER(name) LIKE '%and%' OR LOWER(product_code) LIKE '%and%' OR LOWER(mas_id) LIKE '%and%' OR LOWER(nametype) LIKE '%and%' OR LOWER(comp) LIKE '%and%' OR LOWER(contry) LIKE '%and%' OR LOWER(productID) LIKE '%and%' ) AND ( LOWER(name) LIKE '%1=1%' OR LOWER(product_code) LIKE '%1=1%' OR LOWER(mas_id) LIKE '%1=1%' OR LOWER(nametype) LIKE '%1=1%' OR LOWER(comp) LIKE '%1=1%' OR LOWER(contry) LIKE '%1=1%' OR LOWER(productID) LIKE '%1=1%' )