Rachel Rachel - 1 month ago 29
PHP Question

SQL Error: SQL Syntax Error

Error Message:


SQL Error: 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 domain = 'ard.qc' AND snapshot_id = 2010 AND locale = 'en_US'' at line 1


SQL Query:

SELECT
entity_id,
content_id
FROM collateral_cms_mapping
WHERE entity_id IN ({$entity_ids})
AND domain = '{$this->getSite()->getInternalId()}'
AND snapshot_id = {$this->getSnapshotDao()->getCurrentSnapshot()}
AND locale = '{$locale}'


Actual SQL after the value is replaced and string concatenation:

SELECT
entity_id,
content_id
FROM
collateral_cms_mapping
WHERE
entity_id
IN
()
AND
domain = 'ard.qc'
AND
snapshot_id = 2009
AND
locale = 'en_US'


Any suggestions?

Wim Wim
Answer

What's the value of $entity_ids? Probably it's empty, so your query contains IN () which is invalid.