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

1.2.4 Phalcon\Db\Adapter\Pdo\Postgresql transaction

Hi all!!!

I use transaction:

try {
    $this->di->getDb()->begin();

    $this->di->getDb()->execute('...');
    $this->di->getDb()->execute('...');

    $this->di->getDb()->commit();
} catch(Exception $e) {
    $this->di->getDb()->rollback();
    echo $e->getMessage();
}

falls exception: Uncaught exception 'Phalcon\Db\Exception' with message 'There is no active transaction'

in Postgres logs: 2013-12-18 20:15:09 TJT ОТМЕТКА: оператор: BEGIN 2013-12-18 20:15:09 TJT ОТМЕТКА: оператор: ROLLBACK

????



98.9k

Are you registering the 'db' service as shared?



42.1k
/**
 * Database connection is created based in the parameters defined in the configuration file
 */
$di->set('db', function() use ($config) {
    return new Postgresql(array(
        'host' => $config->database->host,
        'username' => $config->database->username,
        'password' => $config->database->password,
        'dbname' => $config->database->dbname
    ));
});


98.9k
Accepted
answer

It must be shared, or every time you call $this->di->getDb() you will get a new connection



42.1k

sorry for my carelessness