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

Class '{className}' does not have a method '{name}'

Error message

Class '{className}' does not have a method '{name}'

What it means

The connection classes forward unknown method calls through __call() to the underlying \PDO instance. If method_exists() on the PDO object is false, UnknownDriverMethod is thrown: you called a method that is neither defined on the connection class itself nor a real PDO method.

Source

Thrown at phalcon/DataMapper/Pdo/Connection/AbstractConnection.zep:88

     *
     * @param string $name
     * @param array  $arguments
     *
     * @return mixed
     * @throws BadMethodCallException
     */
    public function __call(var name, array arguments)
    {
        var className, message;

        this->connect();

        if !method_exists(this->pdo, name) {
            let className = get_class(this),
                message   = "Class '" . className
                          . "' does not have a method '" . name . "'";

            throw new UnknownDriverMethod(message);
        }

        return call_user_func_array(
            [
                this->pdo,
                name
            ],
            arguments
        );
    }

    /**
     * Begins a transaction. If the profiler is enabled, the operation will
     * be recorded.
     *
     * @return bool
     */
    public function beginTransaction() -> bool

View on GitHub (pinned to b7419de9cd)

Solutions

  1. Use the connection's own fetch* helpers (fetchOne, fetchAll, etc.) or query()/prepare() and call statement methods on the returned PDOStatement
  2. Check the PHP PDO method list — only PDO methods can be forwarded
  3. Fix typos; the message names the class and the missing method
  4. No special setup is needed — the connection connects automatically before forwarding valid calls

Example fix

// before
$user = $connection->fetchObject('User'); // not a Connection or PDO method

// after
$stmt = $connection->query('SELECT * FROM users WHERE id = 1');
$user = $stmt->fetchObject('User');
Defensive patterns

Strategy: validation

Validate before calling

$method = 'fetchObject';
if (!method_exists($connection, $method) && !method_exists(\PDO::class, $method)) {
    throw new BadMethodCallException(
        get_class($connection) . " has no method '{$method}' (and PDO does not either)"
    );
}
return $connection->{$method}(...$args);

Try / catch

use Phalcon\DataMapper\Pdo\Exception\UnknownDriverMethod;

try {
    $result = $connection->{$name}(...$args);
} catch (UnknownDriverMethod $e) {
    throw new BadMethodCallException('Invalid DB call: ' . $e->getMessage(), 0, $e);
}

Prevention

When it happens

Trigger: Calling PDOStatement-level methods on the connection (fetchObject, execute, bindParam) instead of on the statement; habits from other DB libraries (Doctrine DBAL, mysqli) like ->executeQuery(); typo'd method names (->querry()); helper methods you expected the wrapper to provide.

Common situations: Mixing API styles when migrating from another DBAL; calling data-access helpers that live on the statement, not the connection; stale method names after upgrading.

Related errors


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