Re: DataObject Transactions

From: Date: Wed, 19 Jan 2005 19:26:10 +0000
Subject: Re: DataObject Transactions
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17024@lists.php.net to get a copy of this message
On Wed, 19 Jan 2005 07:49:35 -0800, Ed Greenberg <edg@greenberg.org> wrote: > Back in September, 2004, there was a discussion of transactions in > DB_DataObject. From that I extrapolated this example: > --- > $errors = 0; > > $person = DB_DataObject::factory('person'); > > $person->query('BEGIN'); > > $mom = DB_DataObject::factory('mom'); > $mom->name = 'Mary'; > $mom_id = $mom->insert(); > if (!$mom_id) $errors++; > > $person->name = 'Fred'; > $person->mom_id = $mom_id; > $res = $person->insert(); > if (!$res) $errors++; > > if ($errors == 0) $person->query('COMMIT'); > else $person->query('ROLLBACK'); > --- > I note that we have two objects, $person and $mom. > > Where do I call BEGIN, COMMIT and ROLLBACK? On $person? on $mom? on either? > > I am using MySQL 4 > When you use query() it's not actually table-specific. The only way it would make a different what object you called it on if if they're using different connections. But since they (should be) connected with the same DSN they'll be on the same connection. The message behind all that is that it doesn't matter. You could even do BEGIN on $person and COMMIT on $mom and it would still work as expected. -- Justin Patrin

« previous php.pear.general (#17024) next »