Re: PEAR::DB and transactions

From: Date: Mon, 14 Jun 2004 14:54:27 +0000
Subject: Re: PEAR::DB and transactions
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-13144@lists.php.net to get a copy of this message
"Tony Bibbs" <tony@tonybibbs.com> wrote in message news:1087224740.2925.24.camel@linux.local... > I have a program I'm writing that needs to use transactions if that > feature is supported by the DBMS. In reading here: > > > http://pear.php.net/manual/en/package.database.db.db-common.provides.php > > I see I can check if the DBMS supports transaction which is great. > However, I don't see anything here: > > http://pear.php.net/manual/en/package.database.php > > that suggests how to wrap things into a transaction. Obviously the fact > provides() even exists tells me there is some methods in the PEAR::DB > manual that isn't showing up that is probably here. So my question is, > how to I start, stop and rollback transactions with PEAR::DB? You can do this (simplified): $errors = 0; // start transaction $db->autocommit(false); // 1st query $result = $db->query($query1); if (DB::isError($result)) $errors++; // 2nd query $result = $db->query($query2); if (DB::isError($result)) $errors++; // and so on // rollback if errors occurred if ($errors) { $db->query('ROLLBACK'); } else { $db->query('COMMIT'); } $db->autocommit(true); Hope this helps. Regards, Torsten Roehr

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