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 'AND excluido IN ('0','2') ORDER BY ordem LIMIT 1' at line 1 - SELECT `contato_img`.* FROM `contato_img` WHERE contatoFK = AND excluido IN ('0','2') ORDER BY ordem LIMIT 1