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 use $bindTypes in query, execute, fetchOne, fetchAll

https://docs.phalconphp.com/en/latest/api/Phalcon%5Db%5Adapter%5Pdo%5Postgresql.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;};


99.5k
Accepted
answer

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

Whitch is correct?

\Phalcon\Db\Column::BINDPARAMBLOB 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
            ]
        );