Reputation: 1050
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
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