cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

PDO FetchMode feature

Open Cmssspl opened this issue 13 years ago • 1 comments

$pdo = new \Phalcon\Db\Adapter\Pdo\Mysql($config->database->toArray());
$pdo->setFetchMode(Phalcon\Db::FETCH_ASSOC);

I know that I used this improperly, but there should be posibility to set fetch mod for all queries. Is there any? Or could someone add that? It is sick to use this for every query when I use only assoc arrays.

Cmssspl avatar Feb 08 '13 10:02 Cmssspl

You can override the query method to assign that to every resultset produced:

<?php

class MysqlAdapter extends \Phalcon\Db\Adapter\Pdo\Mysql
{

    public function query($sqlStatement, $bindParams=null, $bindTypes=null)
    {
        $result = parent::query($sqlStatement, $bindParams, $bindTypes);
        $result->setFetchMode(\Phalcon\Db::FETCH_ASSOC);
        return $result;
    }

}

ghost avatar Feb 09 '13 03:02 ghost