Phalcon Resultset incorrect data types


I have a strange behaviuor with Phalcon result set. i am using version 2.0. I have a table called user with primary key _id defined as BIGINT, name as varchar, status as INT. When i query

$user = User::findFirt();
array(3) {
    string(1) "2"
    string(5) "admin"
    string(1) "1"

The expected result is _id & status is integer.

Appreciate help. Thanks in advance.

edited Aug '16

I think this is default behaviour of many ORM's, atleast it is like that in many other popular frameworks I've worked with (if i remember well).

You can do the following if you really need integers. In your Model:

public function afterFetch()
    $this->_id = (int) $this->_id;
    $this->status = (int) $this->status;

edited Aug '16

I use this

$class = new \Phalcon\Db\Adapter\Pdo\Mysql([
                'host' => $config->database->host,
                'username' => $config->database->username,
                'password' => $config->database->password,
                'dbname' => $config->database->dbname,
                'port' => '3306',
                'charset' => 'utf8',
                "options"  => [
                    \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
                    \PDO::ATTR_PERSISTENT => true,
                    \PDO::ATTR_EMULATE_PREPARES => false,
                    \PDO::ATTR_DEFAULT_FETCH_MODE  =>  \PDO::FETCH_ASSOC,
                    \PDO::ATTR_STRINGIFY_FETCHES => false  // <----------------------------------------

Nice one @Izo, didn't know that. Updating my bootrsap. Thanks ! : )

Also you need to use mysqlnd driver.


Hi, thanks for your help. Izo, it didn't worked as expected. I implemented afterFetch().