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 '[SECTIONS.BEBES.ID] ORDER BY A.dateon DESC LIMIT 0,6' at line 1 QUERY :SELECT A.title as title, 'fg' as ref_type, as ref_id, P.description as description, as coverid, P.title as covertitle FROM Albums as A JOIN Photos as P ON AND P.ord=1 WHERE AND NOT A.nobox AND NOT A.nohome AND A.section = [SECTIONS.BEBES.ID] ORDER BY A.dateon DESC LIMIT 0,6