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 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



98.9k
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?



98.9k

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!!!