Re: pear::db, INNO DB and transactions
| From: | Alan Knowles | Date: | Sat, 13 Dec 2003 02:01:27 +0000 |
| Subject: | Re: pear::db, INNO DB and transactions | ||
| References: | 1 2 3 | Groups: | php.pear.general php.pear.general |
| Request: | Send a blank email to pear-general+get-9493@lists.php.net to get a copy of this message | ||
It's a return by refernce on overloaded object issue! - bug in the php4 overload engine.
just turn of overload - I'm considering making this the default as it seems to be causing to many problems.
Regards
Alan
Demian Turner wrote:
hi markus it's seems there's more than meets the eye in getting transactions to work with dataobject. using a reference to the database resource as your suggest below unfortunately did not fix the problem. in pseudocode, this is what i was trying to do, in MySQL with INNO DB tables: - autocommit = false - begin transaction - create new user dataobject - insert user dataobject - create new address dataobject(user's address details in related table) - insert address dataobject - if no errors ocurred in either query, commit - else rollback this works fine directly in a mysql terminal, and probably in PEAR::DB. but in dataobject it would appear each new dataobject loses track of the transaction. even in the following code that tries to close the gaps, the problem could not be fixed: $oUser = & new DataObjects_Usr(); $dbh = & $oUser->getDatabaseConnection(); $dbh->autoCommit(false); $dbh->query('BEGIN') // add user $oUser->setFrom($input->user); $oUser->user_id = $dbh->nextId('usr'); $oUser->contact_id = $dbh->nextId('contact'); $oUser->passwd = md5($oUser->passwd); $oUser->date_created = $oUser->last_updated = Base::getTime(); $oUser->created_by = $oUser->updated_by = Session::getUid(); $successUser = $oUser->insert(); // update user's contact details $oContact = & new DataObjects_Contact(); $dbh = & $oContact->getDatabaseConnection(); $dbh->autoCommit(false); $oContact->setFrom($input->contact); $oContact->contact_id = $oUser->contact_id; $oContact->last_updated = $oContact->last_updated = Base::getTime(); $oContact->created_by = $oContact->updated_by = Session::getUid(); $successContact = $oContact->insert(); if (!($successContact && $successUser)) {-- Can you help out? Need Consulting Services or Know of a Job? http://www.akbkhome.com$dbh->query('ROLLBACK');} else {// all's well, commit $dbh->query('COMMIT');} anyone got transactions working with dataobjects? cheers demianDemian Turner wrote:calling from DataObject, i used the following code: $oUser = & new DataObjects_Usr(); $db = $oUser->getDatabaseConnection(); $db->autoCommit(false);You should assign the connection object by reference: $db =& $oUser->getDatabaseConnection(); Without the "&", the following call to autoCommit() will only affect the _copy_ of the connection object you've just made, not the one still used by the DataObject. Please test this and post some feedback if this solves the problem. CU Markus