Transaction kohana with orm

Is it possible (how) to use mysql transactions and rollbacks using cohm ORM?

+7
php orm kohana
source share
3 answers

The SQL operations in Kohana 3.x do not work as they did in 2.x. In class 3.x, the database class has transaction methods:

$db->begin(); $db->commit(); $db->rollback(); 

This also works if you use ORM material. Just start the transaction before ORM saves, updates, a or deletes.

More in this post: http://dev.strategystar.net/2011/10/sql-transactions-with-kohana-3-x/

In 2.x, transactions had to be performed manually:

 $this->db->query("START TRANSACTION") 
+8
source share

Check out the official forums . It shows an example of using transactions with Ko3:

 $db->query(NULL, 'TRANSACTION START'); // Do stuff $db->query(NULL, 'COMMIT'); 

How to do this with version 2, I do not know. I am still new to kohan and learn Ko3, not 2. But I guess this is very similar.

+7
source share

I created a Kohana module that simplifies the use of transactions:

https://github.com/brazzy/kohana-transactional

However, this requires at least Kohana 3.1. But then you just add

 public $_transactional = true; 

for the controller, and all actions are automatically performed inside the transaction, which is rolled back when the action fails with an exception.

+3
source share

All Articles