第1行“(#4)中的行来自## whmportfolio_item`行附近的语法错误”

时间:2019-06-08 02:04:47

标签: php sql mariadb

我已将站点从具有mysql服务器的服务器迁移到了具有MariaDB服务器版本的其他站点,并且该站点在旧服务器上正常运行

但是在新版本中,我收到此错误:

  

1064您的SQL语法有错误;检查手册   对应于您的MariaDB服务器版本,以使用正确的语法   位于“ #__whmportfolio_item行来自{4)的行中”附近   第1行

这是该模块的辅助代码:

<?php

    class ModWhmPortfolioHelper
    {
        public static function toggleVoteAjax() {
        $db = JFactory::getDbo();
        $u = WhmportfolioFrontendHelper::getUid();
        $pfid = JRequest::getInt('pfid', 0);
        if(!$pfid) {
            return null;
        }
        $rs = $db
        ->setQuery("SELECT id FROM #__whmportfolio_liked WHERE u = '{$u}'")
        ->loadObject();
        if(is_null($rs)) {
            $db
            ->setQuery("INSERT INTO #__whmportfolio_liked(pfid, u) VALUES ({$pfid}, '{$u}')")
            ->execute();
        }
        else {
            $db
            ->setQuery("DELETE FROM #__whmportfolio_liked WHERE id = {$rs->id}")
            ->execute();
        }

        return $db
        ->setQuery("SELECT count(*) as c FROM #__whmportfolio_liked WHERE u = '{$u}'")
        ->loadObject()->c;
    }

    public static function getItems($cate, $tag, $offset, $limit, $isize='0x0'){
        $db = JFactory::getDbo();
        $uid = WhmportfolioFrontendHelper::getUid();
        $where = "";
        if($tag || $cate) {
            $where = "WHERE ";
            if($tag) {
                $tag = implode(',', $tag);
                $where .= "a.tag in ({$tag})";
            }
            if($tag && $cate) {
                $where .= " AND ";
            }
            if($cate) {
                $cate = implode(',', $cate);
                $where .= "a.cate in ({$cate})";
            }
        }
        $q = 'SELECT DISTINCT a.*,'.
            "(select count(*) from #__whmportfolio_liked as l where l.pfid = a.id) as cliked,".
            "(select count(*) from #__whmportfolio_liked as l where l.u = '{$uid}') as lactive
            FROM `#__whmportfolio_item` AS a
            {$where}
            ORDER BY a.id DESC";
        $rs = $db->setQuery($q, $offset, $limit)->loadObjectList();
        if(is_null($rs)) return 0;

        foreach($rs as &$item) {
            WhmportfolioFrontendHelper::build($item, $isize);    
        }

        $q = "SELECT DISTINCT count(*) as rows FROM `#__whmportfolio_item` AS a {$where}";
        return (object)array('items'=>$rs, 'total'=>$db->setQuery($q)->loadObject()->rows);
    }


    }

?>



1 个答案:

答案 0 :(得分:0)

#引入了一个注释,该注释一直持续到行尾。

要在表名中使用#,请使用反引号将其引号:

  ->setQuery("DELETE FROM `#__whmportfolio_liked` WHERE id = {$rs->id}")
                          ^                     ^