pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Treat <xzilla@users.sourceforge.net>
To: Rick Morris <rick@brainscraps.com>
Cc: pgsql-php@postgresql.org
Subject: Re: PostgreSQL locking from PHP scripts
Date: Tue, 7 Nov 2006 23:32:35 -0500
Message-ID: <200611072332.35966.xzilla@users.sourceforge.net> (raw)
In-Reply-To: <45503BD3.4090405@brainscraps.com>
References: <20061026181147.50048.qmail@web51309.mail.yahoo.com>
	<200611062334.59629.xzilla@users.sourceforge.net>
	<45503BD3.4090405@brainscraps.com>

On Tuesday 07 November 2006 02:54, Rick Morris wrote:
> Robert Treat wrote:
> > On Monday 06 November 2006 20:24, Chris wrote:
> >> Herbie McDuck wrote:
> >>> Alan Hodgson wrote:
> >>>> On Thursday 26 October 2006 11:11, Amal burman <amalburman@yahoo.com>
> >>>>
> >>>> wrote:
> >>>>> postgresql database for this project. Here script one
> >>>>> (booking.php) tries to setup a lock for update and ask
> >>>>> user to fill-up the form. Now when the user fill-up
> >>>>> the form and submit it for update, second script
> >>>>> (update.php) update the database and releasing the
> >>>>> locks.
> >>>>
> >>>> You can't do this kind of thing in PHP.  PHP resets the database
> >>>> connection between scripts.   The script is finished as soon as the
> >>>> page is delivered to the client.
> >>>>
> >>>> Also, web connections are stateless and there is no way to even know
> >>>> what web server process or database connection you'll be getting on
> >>>> subsequent page views.
> >>>
> >>> So is PHP and 'ANY' database a useless adventure when it goes to
> >>> developing a robust business and accounting package?
> >>
> >> No, it applies to anything you do in a web browser.
> >>
> >> The HTTP protocol is "stateless" which means all resources, connections
> >> etc are killed at the end of the script. Resources of any type are not
> >> kept alive at the end of a script.
> >>
> >> It's not a php thing or <insert random language here>, it's a HTTP
> >> protocol thing.
> >
> > In theory you can use prepared transactions to get around this, but I've
> > never seen anyone fully implement it in PHP.
>
> How exactly would that work? With PDO Prepare/Execute? Would you prepare
> a transaction, and then store the PDOStatement object as a session var?
>

Your thinking of prepared statements, which are something different entirely. 
I'm talking about prepared transactions, which are typically used for 2 phase 
commit implementations. 
http://www.postgresql.org/docs/8.1/interactive/sql-prepare-transaction.html

> Or do you mean this is something that would have to be implemented in
> PHP internals?

Actually it canall be done at the SQL level, although if you were going to do 
it seriously I'd suspect that you'd want to add some php internal functions 
to do it, though aiui there aren't any knobs you'd get from libpq to do this, 
so not sure what that would like like on the php end.  

In any case upon a bit more reflection prepared transactions really wouldn't 
allow you to do what the OP wanted, so it's all kind of moot.  

-- 
Robert Treat
Build A Brighter LAMP :: Linux Apache {middleware} PostgreSQL



view thread (12+ messages)

Message-ID: <200611072332.35966.xzilla@users.sourceforge.net>
Permalink:  ../200611072332.35966.xzilla@users.sourceforge.net/
Also on:    postgresql.org/message-id/200611072332.35966.xzilla@users.sourceforge.net

 · 

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: xzilla@users.sourceforge.net, rick@brainscraps.com
  Subject: Re: PostgreSQL locking from PHP scripts
  In-Reply-To: <200611072332.35966.xzilla@users.sourceforge.net>
  References: <20061026181147.50048.qmail@web51309.mail.yahoo.com> <200611062334.59629.xzilla@users.sourceforge.net> <45503BD3.4090405@brainscraps.com> <200611072332.35966.xzilla@users.sourceforge.net>

* 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