phalcon/cphalcon · error · Phalcon\DataMapper\Pdo\Exception\UnknownQueryMethod

Unknown method: [{method}]

Error message

Unknown method: [{method}]

What it means

Thrown by the magic __call() of Phalcon\DataMapper\Query\Select. Select proxies exactly ten connection methods to the underlying connection: fetchAffected, fetchAll, fetchAssoc, fetchCol, fetchGroup, fetchObject, fetchObjects, fetchOne, fetchPairs, fetchValue (hardcoded whitelist in Select.zep lines 65-76). Any other method name falls through to 'throw new UnknownQueryMethod(method)'. The exception extends PHP's BadMethodCallException, so it is a pure developer-error signal, not a runtime condition to recover from.

Source

Thrown at phalcon/DataMapper/Query/Select.zep:94

        ];

        if likely isset proxied[method] {
            return call_user_func_array(
                [
                    this->connection,
                    method
                ],
                array_merge(
                    [
                        this->getStatement(),
                        this->getBindValues()
                    ],
                    params
                )
            );
        }

        throw new UnknownQueryMethod(method);
    }

    /**
     * Sets a `AND` for a `HAVING` condition
     *
     * @param string     $condition
     * @param mixed|null $value
     * @param int        $type
     *
     * @return Select
     */
    public function andHaving(
        string condition,
        var value = null,
        int type = -1
    ) -> <Select> {
        this->having(condition, value, type);

View on GitHub (pinned to b7419de9cd)

Solutions

  1. Use one of the ten proxied names: fetchAffected, fetchAll, fetchAssoc, fetchCol, fetchGroup, fetchObject, fetchObjects, fetchOne, fetchPairs, fetchValue
  2. For a single scalar use fetchValue(); for one column across rows use fetchCol(); for key-value pairs use fetchPairs()
  3. If you need a non-proxied connection method, run the statement yourself: $connection->fetchAll($select->getStatement(), $select->getBindValues())
  4. Fix typos: fetchcolumn -> fetchCol, fetchone -> fetchOne, fetchPair -> fetchPairs

Example fix

// before
$id = $select->fetchColumn();

// after
$id = $select->fetchCol();   // or fetchValue() for a single scalar
Defensive patterns

Strategy: type-guard

Type guard

/** Methods Select::__call actually proxies to the connection. */
function isProxiedSelectMethod(string $method): bool
{
    return in_array($method, [
        'fetchAffected', 'fetchAll', 'fetchAssoc', 'fetchCol', 'fetchGroup',
        'fetchObject', 'fetchObjects', 'fetchOne', 'fetchPairs', 'fetchValue',
    ], true);
}

// before a dynamic call:
if (!isProxiedSelectMethod($method)) {
    throw new LogicException("Select cannot proxy '{$method}'");
}
$select->{$method}(...$args);

Prevention

When it happens

Trigger: Calling a fetch method outside the whitelist on a Select object: $select->fetchColumn() (the real name is fetchCol()), $select->fetchRow(), $select->fetchScalar() (real name fetchValue()), or a typo like fetchone(). Also calling a Connection-level method that was never proxied (e.g. $select->fetchAffected() is proxied but $select->query() is not), or a query-building method that does not exist on Select.

Common situations: Copy-pasting PDO/PDOStatement calls (fetchColumn, fetchAll with fetch mode args) onto a Select object; porting code between Atlas/Aura.Sql Query objects and Phalcon's DataMapper Select; IDE autocompletion suggesting a similarly named method; upgrading from an older Phalcon version where a fetch alias existed.

Related errors


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/b102476af9a27204. Report an issue: GitHub.