dba->db->inTransaction()) { $this->active = $this->dba->db->beginTransaction(); } } /** * Roll back the transaction if it is active and not already committed. */ public function __destruct() { if ($this->active && ! $this->committed) { $this->dba->db->rollBack(); } } /** * Commit the transaction if active. * * This will also mark the transaction as committed, preventing it from * being attempted rolled back on destruction. */ public function commit(): void { if ($this->active && ! $this->committed) { $this->committed = $this->dba->db->commit(); } } }