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