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 'AND userid <> 0 AND (timeTo='2017-7' OR timeTo > '2017-7' OR timeTo='-')' at line 1