You are here: PDO: determining if a transaction is active « PHP Programming Language « IT news, forums, messages
PDO: determining if a transaction is active

Posted by Gordon on 12/18/07 17:31

I am currently working on some code for my CMS that creates a site
folder, then creates all the necessary child folders inside it. The
method that creates folders needs to insert into 2 tables so it wraps
the operation in a transaction. (psuedocode below)

public function createItem ($parent)
{
$this -> database -> beginTransaction ();
$this -> database -> query ('INSERT INTO items (param1,
param2 ... ) values (val1, val2 ... )');
$newId = myMethodForGettingInsertId ();
$this -> database -> query ('INSERT INTO folders (id, param3 ... )
values ($newId, val3 ... )');
$this -> database -> commit ();
return ($newId);
}

(the real code is obviously a lot more sophisticated and has all the
error checking and rollbacks and what have you but the mock up code
below is clearer regarding the intent of the method)

In my site creating class I have something along the lines of

public function createItem ($parent)
{
$this -> database -> beginTransaction ();
$newId = parent::createItem ($parent);
parent::createItem ($newId, 'images');
parent::createItem ($newId, 'css');
parent::createItem ($newId, 'other_stuff');
$this -> database -> commit ();
}

This obviously causes an exception. I can take the transaction code
out of my folder class but the creation of a folder should be atomic.
I could leave it out of the site creation class, but I really do need
site creation to be atomic as well.

Is there a way of determining that I am inside a transaction before
attempting to start one?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация