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

How to use $bindTypes in query, execute, fetchOne, fetchAll

https://docs.phalcon.io/en/latest/api/Phalcon_Db_Adapter_Pdo_Postgresql.html

$sql = 'INSERT INTO config ( collection, name, data ) '
                    . ' VALUES (:collection, :name, :data) '
                    . ' ON DUPLICATE KEY UPDATE '
                    . ' data = VALUES(data);';

Is not work:

$this->connection->execute(
            $sql,
            [
                'collection' => $this->collection,
                'name' => $name,
                'data' => $this->encode($data)
            ],
            [
                'collection' => \PDO::PARAM_STR,
                'name' => \PDO::PARAM_STR,
                'data' => \PDO::PARAM_LOB
            ]
        );

Not doc, help me!.

What you mean not work ?

save 'data' as 'string' not as 'obj'.

edited Sep '16

I save:

serialize([1,2,3,4,5,6]);

in database write:

s:54:"a:6:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:5;i:5;i:6;}";

Correct is:

a:6:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:5;i:5;i:6;};


145.0k
Accepted
answer

How this is phalcon related ? You just have somewhere double serialization - that's all.

Whitch is correct?

\Phalcon\Db\Column::BIND_PARAM_BLOB or \PDO::PARAM_LOB

    $this->connection->execute(
            $sql,
            [
                'collection' => $this->collection,
                'name' => $name,
                'data' => $this->encode($data)
            ],
            [
                'collection' => Db\Column::BIND_PARAM_STR,
                'name' => Db\Column::BIND_PARAM_STR,
                'data' => Db\Column::BIND_PARAM_BLOB
            ]
        );

BLOB i guess.

edited Sep '16

ok. Work!.

He was serializing double.

is work:

return (bool)$this->connection->execute(
            $sql,
            [
                'collection' => $this->collection,
                'name' => $name,
                'data' => $data
            ],
            [
                'collection' => Db\Column::BIND_PARAM_STR,
                'name' => Db\Column::BIND_PARAM_STR,
                'data' => Db\Column::BIND_PARAM_BLOB
            ]
        );