dongmei2002
2015-08-03 13:17
浏览 222
已采纳

SQLSTATE [42000]:语法错误或访问冲突:1065查询为空(SQL :)

I have PHP class as follow:

class SearchAttributeDao extends BaseDao
{
    private $SELECT_CATEGORY_FILTER_BY_IDS;

    function __construct()
    {
        $this->table_name = 'categoryattributes';
        $this->SELECT_CATEGORY_ATTR_BY_IDS = "SELECT csa.attributeid, atn.name FROM "
            .$this->table_name.
            " csa join attributenames atn on csa.attributeid = atn.attributeid where csa.categoryid in (?); ";
    }

    public function getListByCatIds(array $catIds)
    {
        //...
        $attr_list = $this->executeSelectQuery($this->SELECT_CATEGORY_FILTER_BY_IDS, [$catIds]); //Error on this line
        //...
    }
}

So when I executes my application I get an error stating:

SQLSTATE[42000]: Syntax error or access violation: 1065 Query was empty (SQL: ) ... at BaseDao->executeSelectQuery(null, array(array('10523', '10524', '10606', '10423', '10533', '10618'))) in SearchAttributeDao.php line 24

The stacktrace above suggest that SELECT_CATEGORY_FILTER_BY_IDS is null or empty but I have set it in constructor. What I have done wrong?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxiang3978 2015-08-03 13:22
    已采纳

    Your are calling:

    $this->executeSelectQuery($this->SELECT_CATEGORY_FILTER_BY_IDS..
    

    but you have defined:

    $this->SELECT_CATEGORY_ATTR_BY_IDS = "SELECT csa.attributeid,...
    

    Try to correct names and try again

    点赞 评论

相关推荐 更多相似问题