We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Database - Phalcon\Db fetch constants

I don't know if it's a bug, but since you use the PDO layer, the constants for fetching records, should have the same value as in PDO.

For example, now you have:

const FETCH_ASSOC = 1; // Should be 2 const FETCH_BOTH = 2; // Should be 4 const FETCH_NUM = 3; // It is ok const FETCH_OBJ = 4; // Should be 5 as in PDO

If you don't correct this, running the following code, will not return the records as expected (object)

    $db = $this->getDI()->get('db')->getInternalHandler();

    $result = $db->query($s_query);
    $result->setFetchMode(\Phalcon\Db::FETCH_OBJ);
    return $result->fetchAll();

But if you replace \Phalcon\Db::FETCH_OBJ with 5 or \PDO::FETCH_OBJ, it works as expected.

Phalcon 1.1.0



98.9k

When you get the internal handler you're working over the PDO instance and not with Phalcon\Db\Adapter*, of course you need to use PDO constants there



51.2k

Ok. Thank you.