Juan Felipe Alavarez Saldarriaga wrote:
>
> So I'm saving some user data into the save method, that method have a
> transaction started, then I call the saveUserGroups method on the same
> class and it have another
> transaction started, is possible to, I don't know, get the transaction
> started in the save method ? cause I got a fatal error that another
> transaction is started.
>
This illustrates the difficulty of trying to control transactions in an
object-oriented way. Transactions are by their nature not object-oriented,
they are global to the DB connection.
I infer from your code sample that the calling app can use either save() or
saveUserGroups() in different circumstances, so both need to be callable as
public methods. But you still need to ensure that the transaction is
started only once.
For example, here is some partial code (I've left out stuff so it is more
brief):
class MyUsersClass
{
public function save() {
$this->objDb->beginTransaction();
$this->_saveUserGroups(); // call protected method
$this->objDb->commit();
}
public function saveUserGroups() {
$this->objDb->beginTransaction();
$this->_saveUserGroups(); // call protected method
$this->objDb->commit();
}
protected function _saveUserGroups()
{
// no transaction controls - rely on caller
$this->objDb->insert( ... );
...
}
}
Regards,
Bill Karwin
--
View this message in context:
http://www.nabble.com/Zend_Db-Transactions---How-to-get-a-initiate-transaction---tp15960812s16154p15995010.html
Sent from the Zend Framework mailing list archive at Nabble.com.