Transactions Across Objects
Posted: Thu Jan 16, 2003 1:29 am
I have been trying to incorporate object oriented code into PHP and all my SQL queries happen through low level data access classes. I use PHPLIB for my database access with persistent connection. I am using the InnoDB handler and have added 3 new functions called begin(), commit() and rollback() to my PHPLIB mysql class.
I am faced with a problem of maintaining transaction thru multiple objects. assuming that my class structure is as follows
class SubClass {
SubClass() {
$sql = "insert into";
$db = new DB;
$res = $db->query($sql);
if(!$res)
$db->rollback();
}
}
class MainClass {
var $obj1;
var $obj2;
MainClass() {
$db = new DB;
$db->begin();
$obj1 = new SubClass;
$obj2 = new SubClass;
$db->commit();
}
}
this is a rough picture, is this strategy bad, if so what could i use to ensure transactions involving multiple object.
More specifically, does a persistent connection mean that the transaction state is also maintained over multiple connections ?
Thanks in advance
I am faced with a problem of maintaining transaction thru multiple objects. assuming that my class structure is as follows
class SubClass {
SubClass() {
$sql = "insert into";
$db = new DB;
$res = $db->query($sql);
if(!$res)
$db->rollback();
}
}
class MainClass {
var $obj1;
var $obj2;
MainClass() {
$db = new DB;
$db->begin();
$obj1 = new SubClass;
$obj2 = new SubClass;
$db->commit();
}
}
this is a rough picture, is this strategy bad, if so what could i use to ensure transactions involving multiple object.
More specifically, does a persistent connection mean that the transaction state is also maintained over multiple connections ?
Thanks in advance