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 execute a SET statement on connect with phalcon/postgres?

hi,

I need execute a SET statement on connect to postgres database.

ex:

SET a.b TO "value1";

SET a.c TO "value2";

and this needs run each connection.

is it possible?

sorry, my english is bad...

tanks



84.5k
Accepted
answer

Add them to your connection:

<?php

$di['db'] = function() {

    // Create a connection
    $connection = new \Phalcon\Db\Adapter\Pdo\Postgresql(array(
        "host" => "localhost",
        "username" => "postgres",
        "password" => "secret1",
        "dbname" => "template"
    ));

    $connection->execute('SET a.b TO "value1"');
    $connection->execute('SET a.c TO "value2"');

    return $connection;
};

TANKS!!!

solved!!!

last question: in this case, the connection is called only when needed?



84.5k

Yes, it will be created the first time the connection is requested, the second time and so on the same connection will be returned

ok!!!

tanks!!!