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?

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