简体   繁体   中英

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?

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

You do not have to concatenate your strings.

It looks like the prepared query is faulty somewhere in the IN ({$entity_ids}) .

Echo the query string to check your IN statement.

Definitely look at the IN statement. While I'm not familiar with MySQL, I don't believe an empty IN () clause is permitted in DB2 or Oracle (although I won't swear to it).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM