Hi
Is there any way of embedding a couple of database updates or saves in a transaction so that I can roll back if either of the individual saves fail?
I can resort to PHP of course but direct from ChronoForms would be better.
I had thought of using 'Found' 'Not Found' options but that won't help if the second fails after the first succeeds.
Regards
Nick
Hi Nick,
Sorry but I don't understand your question :-(
If this is a multi-page form then you can add a DB Save after each page - does that do what you need?
Bob
Hi Bob
Sorry about that. My situation is that I want to add or update records in two tables. I need to be sure that they both succeed or neither succeeds.
In php I would use, for example:-[pre]$db = JFactory::getDbo();
try[br]{[br] $db->transactionStart();[br] // Table One[br] $query = $db->getQuery(true);[br] [br] $values = array($db->quote('TEST_CONSTANT'), $db->quote('Custom'), $db->quote('/path/to/translation.ini'));[br] [br] $query->insert($db->quoteName('#__TableOne'));[br] $query->columns($db->quoteName(array('constant', 'string', 'file')));[br] $query->values(implode(',',$values));[br][br] $db->setQuery($query);[br] $result = $db->execute();[br] // Table Two[br] $query = $db->getQuery(true);[br] [br] $values = array($db->quote('TEST_CONSTANT'), $db->quote('Custom'), $db->quote('/path/to/translation.ini'));[br] [br] $query->insert($db->quoteName('#__TableTwo'));[br] $query->columns($db->quoteName(array('constant', 'string', 'file')));[br] $query->values(implode(',',$values));[br][br] $db->setQuery($query);[br] $result = $db->execute();[br][br][br] $db->transactionCommit();[br]}[br]catch (Exception $e)[br]{[br] // catch any database errors.[br] $db->transactionRollback();[br] JErrorPage::render($e);[br]}[/pre]
So my question is - can I deal with changes to several database tables directly in ChronoForms? I know that I could use two database functions where the change to __tableTwo only runs if the change to _tableOne runs OK by embedding the change to tableTwo in the record found event for tableOne but can't see how I might roll back the change to tableOne if the change to tableTwo fails.[br][br]