Subject RE: [firebird-php] Is transaction correct ?
Author Alan McDonald
I think it depends on what type of scripting you are doing. I use it with a
webserver and it's all page based. I don't need to specify a transaction
since every page has it's own transaction context.
every time I call an ibase_query function, the function returns true is
successfull and no errors occurred.
So if I reach the point after serveral queries (e.g. updates, selects, etc)
where I need to decide, the I just examine the retun values
e.g.
$myreturn = @ibase_query( etc
$mysecondreturn = @ibase_query( another statement)
now at the time I need to decide to commit or rollback I do this

if ($myreturn &&$mysecondreturn) {
ibase_commit();
header("Location: a page I want to go when everything is OK);
} else {
ibase_rollback();
if (!$myreturn) echo "<font color='red'>There has been an
<b>error</b> inserting the [first] as supplied, please try again and/or use
the etc, etc.</font>";
if (!$mysecondreturn) echo "<font color='red'>There has been an
<b>error</b> inserting the [second record] as supplied, please try again
and/or use the etc </font>";
}

Alan
PS. In the odd event that you need a second transaction on the same page,
then you will have to start one manually.
-----Original Message-----
From: firebird-php@yahoogroups.com [mailto:firebird-php@yahoogroups.com]On
Behalf Of Uwe Oeder
Sent: Monday, 13 June 2005 5:42 PM
To: firebird-php@yahoogroups.com
Subject: [firebird-php] Is transaction correct ?


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) ;
}


----------------------------------------------------------------------------
--
Yahoo! Groups Links

a.. To visit your group on the web, go to:
http://groups.yahoo.com/group/firebird-php/

b.. To unsubscribe from this group, send an email to:
firebird-php-unsubscribe@yahoogroups.com

c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



[Non-text portions of this message have been removed]