Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to set default fetch mode?

I work with Phalcon\Db\Adapter\Pdo\Mysql directly. And i want to change default fetch mode.

In PDO i can do this:

$connection = new PDO($options); $connection->setAttribute(PDO::ATTRDEFAULTFETCHMODE, PDO::FETCHOBJ);

For example you can get array this way: $robots = Robots::find()->toArray();


$robots = Robots::find( array('hydration' => Resultset::HYDRATE_ARRAYS) );

Check out hydration mode in documentation, there are very detailed information


You can try this

        $connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array(
            'host' => 'localhost',
            'dbname' => 'phalcon',
            'username' => 'root',
            'password' => '',
            'options' => [PDO::ATTR_CASE => PDO::CASE_LOWER, PDO::ATTR_PERSISTENT => TRUE,],

Marcio Paiva, that's what I meant. Thanks!

Is Marcio Paiva's way success? I try to set [PDO::ATTRDEFAULTFETCHMODE => PDO::FETCHASSOC] but it still return both assoc and array.

the following is

new \Phalcon\Db\Adapter\Pdo\Mysql(array(
        'host' => $config->database->host,
        'username' => $config->database->username,
        'password' => $config->database->password,
        'dbname' => $config->database->dbname,
        'charset' => $config->database->charset,
        'options' =>

there is a similar problem solved by overiding the query function.