Hey I am having some trouble using the built in model begin() ,
commit(), etc .. in cakePHP 1.2 . Does anyone know if transactions are
working properly ? Below is some code that simply does an insert on a
table that has an auto_incrementing id, and then retrieves max ID ,
and does some more insertions with that ID on another table.
Problem is I need to make sure everything goes through and rollback if
it breaks so that I don't have inconsistent data across 2 tables.
Any help is appreciated , thank you!
The code below doesn't work, it inserts and everything but doesn't
rollback on broken transactions.
// Start our transaction
$this->User->begin();
//Save user_data table
$user_table_data = some array of data
if($this->User->save($user_table_data))
{
$sql = "SELECT MAX(id) as maxID FROM users";
$maxID = $this->User->query($sql);
$uid = $maxID[0][0]['maxID'];
$this->Account->begin();// Start our transaction to insert acount
info
if($this->__saveAccountInformation(trim($account_type),$uid,
$encrypted_pwd)) //save account information.
{
// Persist the data
$this->User->commit();
$this->Account->commit();
$this->redirect('/edit_settings');
exit();
}
else
{
$this->Account->rollback();
$this->User->rollback();
}
}
else
{
$this->User->rollback();
}
Thanks
Manu
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---