0

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.

LCB
  • 971
  • 9
  • 22

1 Answers1

2

$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 );
LCB
  • 971
  • 9
  • 22