pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Legault <legault.david@gmail.com>
To: mikie <mikie.pl@gmail.com>
Cc: pgsql-php@postgresql.org
Subject: Re: transactions from PHP - double COMMIT required?
Date: Thu, 1 Mar 2007 07:18:54 -0500
Message-ID: <e0b20d410703010418m3f931527wb2e81e3f3ab0c9f4@mail.gmail.com> (raw)
In-Reply-To: <ca35ce500703010329j329b8a5h6ee8958ddb6711e0@mail.gmail.com>
References: <ca35ce500703010306nd06dcfcy1247fb2b4297b0c2@mail.gmail.com>
	<20070301131523.fgfm83nb9y2kgo4c@imp3.uta.fi>
	<ca35ce500703010329j329b8a5h6ee8958ddb6711e0@mail.gmail.com>

If you are using PHP5 (and the PDO PGSQL) I would suggest you use exceptions
to trap the error

try {

 $db->beginTransaction();

 // other queries here, if one fails, an exception is thrown

 $db->commit();
}
catch (Exception $e) {

 // do whatever with error
 $db->rollback();
}

On 3/1/07, mikie <mikie.pl@gmail.com> wrote:
>
>
>
> 2007/3/1, Mihail Mihailov <Mihail.Mihailov@uta.fi>:
> >
> > Hi,
> >
> > I think you should use ROLLBACK if the query cannot be executed.
> > one can commit only results of the queries that work.
> > Try ROLLBACK statement.
> >
> > The thing is that when I try my transaction from psql console then the
> command ROLLBACK is being issued by the postgres server itself right after I
> close my transaction with COMMIT;. According to transaction logic and idea -
> if something goes wrong then the entire transaction is being cancelled by
> ROLLBACK - it is the server responsibility to rollback such transaction.
>
> Now, when I try to do some inserts within my transaction I don't know if
> they will fail or not. Eitherway I am closing my transaction with the
> COMMIT; command - is that correct way ?
> It works logically OK from within psql console (I start with BEGIN and
> then close my sql commands with commit) but it does not work this way from
> within PHP script. I believe there is some issue with PHP - I am not sure if
> PHP processor applies some changes to my query and thus ignores the commit
> command?
>
> --
> Mike
>
>

view thread (23+ messages)  latest in thread

Message-ID: <e0b20d410703010418m3f931527wb2e81e3f3ab0c9f4@mail.gmail.com>
Permalink:  ../e0b20d410703010418m3f931527wb2e81e3f3ab0c9f4@mail.gmail.com/
Also on:    postgresql.org/message-id/e0b20d410703010418m3f931527wb2e81e3f3ab0c9f4@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: legault.david@gmail.com, mikie.pl@gmail.com
  Subject: Re: transactions from PHP - double COMMIT required?
  In-Reply-To: <e0b20d410703010418m3f931527wb2e81e3f3ab0c9f4@mail.gmail.com>
  References: <ca35ce500703010306nd06dcfcy1247fb2b4297b0c2@mail.gmail.com> <20070301131523.fgfm83nb9y2kgo4c@imp3.uta.fi> <ca35ce500703010329j329b8a5h6ee8958ddb6711e0@mail.gmail.com> <e0b20d410703010418m3f931527wb2e81e3f3ab0c9f4@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox