Re: transactions from PHP - double COMMIT required?

From: "David Legault" <legault(dot)david(at)gmail(dot)com>
To: mikie <mikie(dot)pl(at)gmail(dot)com>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: transactions from PHP - double COMMIT required?
Date: 2007-03-01 13:16:53
Message-ID: e0b20d410703010516l20edae05oc2a718d4c970fcb5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

Probably because the pgsql extension in PHP has an internal representation
that doesn't fit with what the DB does (auto rollback on error).

it keeps a state of transaction flag as active even though the DB rolled
back when the error occured thus flagging an error when you want to start
another one or execute another query.

BEGIN

Queries

check for error (pg_last_error) after each query, if error, rollback and
exit transaction "block"

COMMIT (no errors found)

The best would be to enclose the query in a function so that you can "exit"
the block with a return statement or some similar construct. I can't
remember if PHP supports block definition like in C

{
// group
// of
// calls
// block
}

David

On 3/1/07, mikie <mikie(dot)pl(at)gmail(dot)com> wrote:
>
> > > But getting back to my problem - perhaps there is something I
> > > misunderstood: is it the client application responsibility to check if
> > > the transaction failed or succeeded and issue COMMIT or ROLLBACK
> > > accordingly (how do I close the transaction block in that case)?
> > > Or is it the database server that is suppose to check if transaction
> > > succeded and perform the query, or ROLLBACK if anything went wrong?
> >
> > PG will rollback all transactions that have an error in some part, as it
> > can't commit the transaction as a whole.
>
> OK, so my way of programming seems correct.
> Then why do I have to send another COMMIT after failed transaction to
> continue with next queries in the same php script ?
>
> --
> Mike
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>

In response to

Browse pgsql-php by date

  From Date Subject
Next Message John DeSoi 2007-03-01 13:40:06 Re: transactions from PHP - double COMMIT required?
Previous Message mikie 2007-03-01 13:02:57 Re: transactions from PHP - double COMMIT required?