我收到以下错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 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 'range join con_cat_lang as catlang join con_cat as cat left join con_frontend' at line 1
有人知道如何解决这个错误吗?我正在使用mySQL 5.5.35
原始查询应为:
$results = $this->db->fetchAll(Con_Db :: tblprefix("" .
"select " .
" concat('|_', concat(repeat('___', count(parent.idcat) - 1), catlang.name)) AS name, " .
" catlang.idcat as idcat, " .
" catlang.name as catname, " .
" catlang.urlname as urlname, " .
" cat.parentid as parentid, " .
" count(parent.idcat) as level, " .
" if (catlang.visible = 1 && (catlang.public = 1 || member.idfrontenduser IS NOT NULL), 1, 0) AS visible " .
"from " .
" con_cat_tree as node " .
" join con_cat_tree as parent " .
" join con_cat_tree as range " .
" join con_cat_lang as catlang " .
" join con_cat as cat " .
" left join con_frontendpermissions as permission ON ((permission.item = catlang.idcatlang OR permission.item = '__GLOBAL__') AND permission.idlang = catlang.idlang AND permission.plugin ='category') " .
" left join con_frontendgroupmembers as member ON permission.idfrontendgroup = member.idfrontendgroup AND member.idfrontenduser = ? " .
"where " .
" node.lft between parent.lft and parent.rgt " .
" and node.lft between range.lft and range.rgt " .
" and node.idcat = catlang.idcat " .
" and parent.tree = ? " .
" and catlang.idlang = ? /* language */ " .
" and catlang.idcat = cat.idcat " .
" and range.idcat = ? /* main category */ " .
" and catlang.idcat != range.idcat " .
" and catlang.visible = 1 /* category online */ " .
" and ( " .
" cat.parentid in ( " .
" select parent.idcat " .
" from " .
" con_cat_tree AS node, " .
" con_cat_tree AS parent, " .
" con_cat_lang AS catlang " .
" where " .
" node.lft BETWEEN parent.lft and parent.rgt " .
" and node.idcat = catlang.idcat " .
" and node.idcat = ? /* selected category */ " .
" and parent.tree = ? " .
" ) " .
" ) " .
"group by node.idcat " .
"order by node.lft" .
""), array (
$this->userId,
$this->idclient,
$this->langId,
$this->startId,
$this->idcat,
$this->idclient
));
答案 0 :(得分:1)
range
是reserved word。你必须逃脱它:
SELECT `reserved` FROM ...
^--------^--- backticks to escape