LCB
LCB

Reputation: 1050

Phalcon transaction not working correct

I created a transaction like this :

$this->db->begin();
$topic = new Topic();
$topic->assign( $data );
$topic->save();

var_dump( $this->db->isUnderTransaction() ); // bool(true)

$this->db->rollback();

var_dump( $this->db->isUnderTransaction() ); // bool(false)

But, the database still changed and inserted a new line. The rollback method is not working.

Upvotes: 0

Views: 418

Answers (1)

LCB
LCB

Reputation: 1050

$di->set method will only be shared if been called with the second parameter is "TRUE".

$di->set( 'db', function() use( $conf ) {
    return new DbAdapter( [
        'host' => $conf->db->host,
        'username' => $conf->db->username,
        'password' => $conf->db->password,
        'dbname' => $conf->db->dbname,
        'options' => [
            \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
            \PDO::ATTR_PERSISTENT => true
        ]
    ] );
}, true );

Upvotes: 2

Related Questions