Subject | Is transaction correct ? |
---|---|
Author | Uwe Oeder |
Post date | 2005-06-13T07:42:14Z |
Is the following the correct way to start a transaction and roll it back
if something goes wrong or is incorrect.
If any exception is raised I let the exception handler catch it and
rollback any changes.
try
{
$this->mydbhandle =
ibase_connect($this->myhost,$this->myusername,$this->mypassword) ;
$this->mytransaction = ibase_trans() ;
foreach ($updatedata as $mydata)
{
$mydbquery = ibase_prepare($this->mydbhandle,$sqlstatement) ;
$rowsaffected = ibase_execute($this->mydbquery) ;
}
ibase_commit($this->mydbhandle) ;
ibase_free_query($this->mydbquery) ;
ibase_close($this->mydbhandle) ;
}
catch (Exception $e)
{
ibase_rollback($this->mytransaction) ;
}
if something goes wrong or is incorrect.
If any exception is raised I let the exception handler catch it and
rollback any changes.
try
{
$this->mydbhandle =
ibase_connect($this->myhost,$this->myusername,$this->mypassword) ;
$this->mytransaction = ibase_trans() ;
foreach ($updatedata as $mydata)
{
$mydbquery = ibase_prepare($this->mydbhandle,$sqlstatement) ;
$rowsaffected = ibase_execute($this->mydbquery) ;
}
ibase_commit($this->mydbhandle) ;
ibase_free_query($this->mydbquery) ;
ibase_close($this->mydbhandle) ;
}
catch (Exception $e)
{
ibase_rollback($this->mytransaction) ;
}