Hi,

Here comes a very simple synchronisation question:

I read the paragraph about transaction in the manual
( http://framework.zend.com/manual/en/zend.db.html#zend.db.adapter.transactions 
)
but couldn't figure out if a transaction is sufficient to deal with
the following situation:

Different processes operate on the same data in a database.
The data is processed in some way and the result is written back after.

Example:

  database state     process 1            process 2
  --------------------------------------------------------
      1              reading 1
      1                                   reading 1
      1              adding 1
      1                                   adding 1
      2              writing back the 
                     result 2
      2                                   writing back the
                                          result 2
  --------------------------------------------------------
  the result is 2
  but should be 3

Sorry for making such a long explanation for something which could be
named easily by one technical term - which I do not remember for the
moment :)

Is the following use of a transaction enough to deal with this
situation?
(code from
http://framework.zend.com/manual/en/zend.db.html#zend.db.adapter.transactions ):

  // Start a transaction explicitly.
  $db->beginTransaction();
  
  try {
  
      ... read the data...
      ... manipulate the data...
      ... write the result back...
  
      $db->commit();
  
  } catch (Exception $e) {
      $db->rollBack();
      echo $e->getMessage();
  }

Or is some other protection required?

Thanks for your help, Dietrich



Reply via email to