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.

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

????



85.0k

Are you registering the 'db' service as shared?



26.6k
/**
 * 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
    ));
});


85.0k
Accepted
answer

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



26.6k

sorry for my carelessness