1

I have a kohana 3.0.14 based website and I want to use transactions in certain models. What is the best approach? Also: how can I use transactions on multiple tables? (how can I block multiple tables simultaneously)? Now I am doing:

   DB::query(NULL, 'START TRANSACTION');            
        $contents = ORM::factory('basket_contents');
        $contents->product_type = $product_type;
        $contents->category = $product->category;
        $contents->basket = $this;
        $contents->save();
   DB::query(NULL, 'COMMIT');

But I want to block 2 tables: basket and contents. Am not convinced that I am doing this right. What is the best approach for using transactions with Kohana 3?

matino
  • 17,199
  • 8
  • 49
  • 58
dana
  • 5,168
  • 20
  • 75
  • 116

2 Answers2

3

Kohana 3 apparently has transaction methods, although they do not appear to be documented. See this link

Transactions are database-level, so anything you do between a start and a commit is part of the transaction, no matter how many tables are involved.

You don't say what DB you are using, but in case you are using MySQL note that MySQL MyISAM tables (the most common type) do not support transactions--you need to use InnoDB with MySql.

Francis Avila
  • 31,233
  • 6
  • 58
  • 96
0

I've created a Kohana module that makes using transactions a lot easier:

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

It does, however, require at least Kohana 3.1 and of course on MySQL also needs tables to use InnoDB.

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720