pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
getting transactions to work
18+ messages / 7 participants
[nested] [flat]

* getting transactions to work
@ 2004-07-30 14:53  reiner peterke <zedaardv@drizzle.com>
  0 siblings, 1 reply; 18+ messages in thread

From: reiner peterke @ 2004-07-30 14:53 UTC (permalink / raw)
  To: pgsql-php

there seems to be very little info around on actually using 
transactions with postgres.  i've tried to create a page that will take 
input from a form and insert it into my database.  it works if i just 
do it without transactions but when i try to use with the begin and 
commit sections of code, it doesn't update the data base.  i'm guessing 
it is doing a rollback when my page loads itself again.  can anyone 
help me out here ?

thanks

r

code below

<html>
<head>
<submitle>those eyes</submitle>
</head>
<body>
   <?
   $conn = pg_connect("dbname=entish user=postgres");
     if(!$conn)
     {
       print "not for the chocolate";
       exit;
     }
   if ($_POST[submit])  {

     $begin = pg_query("begin");
     $isql = "insert into diety(diety,culture,gender)
               values 
('$_POST[diety]','$_POST[culture]','$_POST[gender]')";
     printf("-- %s --\n",$isql);
     $results = pg_query($isql);
     ?>
     <form method="post" action="<? echo $PHP_SELF?>">
       <input type="Submit" name="action" value="commit">
       <input type="Submit" name="action" value="rollback">
     </form>
     <?
   }
   else if(!$_POST[action]) {
   ?>
     <form method="post" action="<? echo $PHP_SELF?>">
       Diety:<input type="text" name="diety"><br>
       Culture:<input type="text" name="culture"><br>
       Gender:<input type="text" name="gender"><br>
       <input type="Submit" name="submit" value="enter">
     </form>
     <?
   }
   else {
     if($_POST[action] == 'commit') {
       echo "let me see";
       $act = pg_query("commit");
     }
     else {
       $act = pg_query("rollback");
       }
   }  //end if $_POST[submit]
?>
</body>
</html> 
   




^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.2] getting transactions to work
@ 2004-07-30 14:57  Rod K <rod@23net.net>
  parent: reiner peterke <zedaardv@drizzle.com>
  0 siblings, 2 replies; 18+ messages in thread

From: Rod K @ 2004-07-30 14:57 UTC (permalink / raw)
  To: reiner peterke <zedaardv@drizzle.com>; +Cc: pgsql-php

You are correct.  You cannot have a transaction span multiple pages/scripts.

reiner peterke wrote:

> there seems to be very little info around on actually using 
> transactions with postgres.  i've tried to create a page that will 
> take input from a form and insert it into my database.  it works if i 
> just do it without transactions but when i try to use with the begin 
> and commit sections of code, it doesn't update the data base.  i'm 
> guessing it is doing a rollback when my page loads itself again.  can 
> anyone help me out here ?
>
> thanks
>
> r
>
> code below
>
> <html>
> <head>
> <submitle>those eyes</submitle>
> </head>
> <body>
>   <?
>   $conn = pg_connect("dbname=entish user=postgres");
>     if(!$conn)
>     {
>       print "not for the chocolate";
>       exit;
>     }
>   if ($_POST[submit])  {
>
>     $begin = pg_query("begin");
>     $isql = "insert into diety(diety,culture,gender)
>               values 
> ('$_POST[diety]','$_POST[culture]','$_POST[gender]')";
>     printf("-- %s --\n",$isql);
>     $results = pg_query($isql);
>     ?>
>     <form method="post" action="<? echo $PHP_SELF?>">
>       <input type="Submit" name="action" value="commit">
>       <input type="Submit" name="action" value="rollback">
>     </form>
>     <?
>   }
>   else if(!$_POST[action]) {
>   ?>
>     <form method="post" action="<? echo $PHP_SELF?>">
>       Diety:<input type="text" name="diety"><br>
>       Culture:<input type="text" name="culture"><br>
>       Gender:<input type="text" name="gender"><br>
>       <input type="Submit" name="submit" value="enter">
>     </form>
>     <?
>   }
>   else {
>     if($_POST[action] == 'commit') {
>       echo "let me see";
>       $act = pg_query("commit");
>     }
>     else {
>       $act = pg_query("rollback");
>       }
>   }  //end if $_POST[submit]
> ?>
> </body>
> </html>  
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend





^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.2] getting transactions to work
@ 2004-07-30 15:03  reiner peterke <zedaardv@drizzle.com>
  parent: Rod K <rod@23net.net>
  1 sibling, 2 replies; 18+ messages in thread

From: reiner peterke @ 2004-07-30 15:03 UTC (permalink / raw)
  To: Rod K <rod@23net.net>; +Cc: pgsql-php

this is meant in all honesty,

then whats the point?!

ok, let me put it this way.  is there no way to implement pages using 
transactions?
otherwise it seems to kind of defeat the purpose of them.

r
On 30 jul 2004, at 16.57, Rod K wrote:

> You are correct.  You cannot have a transaction span multiple 
> pages/scripts.
>
> reiner peterke wrote:
>
>> there seems to be very little info around on actually using 
>> transactions with postgres.  i've tried to create a page that will 
>> take input from a form and insert it into my database.  it works if i 
>> just do it without transactions but when i try to use with the begin 
>> and commit sections of code, it doesn't update the data base.  i'm 
>> guessing it is doing a rollback when my page loads itself again.  can 
>> anyone help me out here ?
>>
>> thanks
>>
>> r
>>
>> code below
>>
>> <html>
>> <head>
>> <submitle>those eyes</submitle>
>> </head>
>> <body>
>>   <?
>>   $conn = pg_connect("dbname=entish user=postgres");
>>     if(!$conn)
>>     {
>>       print "not for the chocolate";
>>       exit;
>>     }
>>   if ($_POST[submit])  {
>>
>>     $begin = pg_query("begin");
>>     $isql = "insert into diety(diety,culture,gender)
>>               values 
>> ('$_POST[diety]','$_POST[culture]','$_POST[gender]')";
>>     printf("-- %s --\n",$isql);
>>     $results = pg_query($isql);
>>     ?>
>>     <form method="post" action="<? echo $PHP_SELF?>">
>>       <input type="Submit" name="action" value="commit">
>>       <input type="Submit" name="action" value="rollback">
>>     </form>
>>     <?
>>   }
>>   else if(!$_POST[action]) {
>>   ?>
>>     <form method="post" action="<? echo $PHP_SELF?>">
>>       Diety:<input type="text" name="diety"><br>
>>       Culture:<input type="text" name="culture"><br>
>>       Gender:<input type="text" name="gender"><br>
>>       <input type="Submit" name="submit" value="enter">
>>     </form>
>>     <?
>>   }
>>   else {
>>     if($_POST[action] == 'commit') {
>>       echo "let me see";
>>       $act = pg_query("commit");
>>     }
>>     else {
>>       $act = pg_query("rollback");
>>       }
>>   }  //end if $_POST[submit]
>> ?>
>> </body>
>> </html>
>> ---------------------------(end of 
>> broadcast)---------------------------
>> TIP 8: explain analyze is your friend
>
>




^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.0] Re: [0.2] getting transactions to work
@ 2004-07-30 15:11  Rod K <rod@23net.net>
  parent: reiner peterke <zedaardv@drizzle.com>
  1 sibling, 1 reply; 18+ messages in thread

From: Rod K @ 2004-07-30 15:11 UTC (permalink / raw)
  To: reiner peterke <zedaardv@drizzle.com>; +Cc: pgsql-php

You can find many resources to explain their purpose better than I can 
do here.

To be honest, I can't see what you are trying to accomplish in your 
script.  If it's validation you should be using session variables to 
store the input AND echoing what was inputed on the validation page.

reiner peterke wrote:

> this is meant in all honesty,
>
> then whats the point?!
>
> ok, let me put it this way.  is there no way to implement pages using 
> transactions?
> otherwise it seems to kind of defeat the purpose of them.
>
> r
> On 30 jul 2004, at 16.57, Rod K wrote:
>
>> You are correct.  You cannot have a transaction span multiple 
>> pages/scripts.
>>
>> reiner peterke wrote:
>>
>>> there seems to be very little info around on actually using 
>>> transactions with postgres.  i've tried to create a page that will 
>>> take input from a form and insert it into my database.  it works if 
>>> i just do it without transactions but when i try to use with the 
>>> begin and commit sections of code, it doesn't update the data base.  
>>> i'm guessing it is doing a rollback when my page loads itself 
>>> again.  can anyone help me out here ?
>>>
>>> thanks
>>>
>>> r
>>>
>>> code below
>>>
>>> <html>
>>> <head>
>>> <submitle>those eyes</submitle>
>>> </head>
>>> <body>
>>>   <?
>>>   $conn = pg_connect("dbname=entish user=postgres");
>>>     if(!$conn)
>>>     {
>>>       print "not for the chocolate";
>>>       exit;
>>>     }
>>>   if ($_POST[submit])  {
>>>
>>>     $begin = pg_query("begin");
>>>     $isql = "insert into diety(diety,culture,gender)
>>>               values 
>>> ('$_POST[diety]','$_POST[culture]','$_POST[gender]')";
>>>     printf("-- %s --\n",$isql);
>>>     $results = pg_query($isql);
>>>     ?>
>>>     <form method="post" action="<? echo $PHP_SELF?>">
>>>       <input type="Submit" name="action" value="commit">
>>>       <input type="Submit" name="action" value="rollback">
>>>     </form>
>>>     <?
>>>   }
>>>   else if(!$_POST[action]) {
>>>   ?>
>>>     <form method="post" action="<? echo $PHP_SELF?>">
>>>       Diety:<input type="text" name="diety"><br>
>>>       Culture:<input type="text" name="culture"><br>
>>>       Gender:<input type="text" name="gender"><br>
>>>       <input type="Submit" name="submit" value="enter">
>>>     </form>
>>>     <?
>>>   }
>>>   else {
>>>     if($_POST[action] == 'commit') {
>>>       echo "let me see";
>>>       $act = pg_query("commit");
>>>     }
>>>     else {
>>>       $act = pg_query("rollback");
>>>       }
>>>   }  //end if $_POST[submit]
>>> ?>
>>> </body>
>>> </html>
>>> ---------------------------(end of 
>>> broadcast)---------------------------
>>> TIP 8: explain analyze is your friend
>>
>>
>>
>




^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.2] getting transactions to work
@ 2004-07-30 15:21  bruce <bedouglas@earthlink.net>
  parent: reiner peterke <zedaardv@drizzle.com>
  1 sibling, 2 replies; 18+ messages in thread

From: bruce @ 2004-07-30 15:21 UTC (permalink / raw)
  To: 'reiner peterke' <zedaardv@drizzle.com>; 'Rod K' <rod@23net.net>; +Cc: pgsql-php

if psgres works as mysql.... you should be able to do it...

but the issue appears to be that the connection you establish with the db in
one page, is not available once you shut the page down.

within mysql, there appears to be a mysqli group of functions that are setup
to accommodate transactions across multiple pages... i would imagine/hope
that the same sort of functionality is available for posgres....

i'm getting close to needing the same functionality with mysql, and i'm
betting/hoping like hell that what i've just described is how mysql/php
works...

-bruce


-----Original Message-----
From: pgsql-php-owner@postgresql.org
[mailto:pgsql-php-owner@postgresql.org]On Behalf Of reiner peterke
Sent: Friday, July 30, 2004 8:04 AM
To: Rod K
Cc: pgsql-php@postgresql.org
Subject: Re: [0.2] [PHP] getting transactions to work


this is meant in all honesty,

then whats the point?!

ok, let me put it this way.  is there no way to implement pages using
transactions?
otherwise it seems to kind of defeat the purpose of them.

r
On 30 jul 2004, at 16.57, Rod K wrote:

> You are correct.  You cannot have a transaction span multiple
> pages/scripts.
>
> reiner peterke wrote:
>
>> there seems to be very little info around on actually using
>> transactions with postgres.  i've tried to create a page that will
>> take input from a form and insert it into my database.  it works if i
>> just do it without transactions but when i try to use with the begin
>> and commit sections of code, it doesn't update the data base.  i'm
>> guessing it is doing a rollback when my page loads itself again.  can
>> anyone help me out here ?
>>
>> thanks
>>
>> r
>>
>> code below
>>
>> <html>
>> <head>
>> <submitle>those eyes</submitle>
>> </head>
>> <body>
>>   <?
>>   $conn = pg_connect("dbname=entish user=postgres");
>>     if(!$conn)
>>     {
>>       print "not for the chocolate";
>>       exit;
>>     }
>>   if ($_POST[submit])  {
>>
>>     $begin = pg_query("begin");
>>     $isql = "insert into diety(diety,culture,gender)
>>               values
>> ('$_POST[diety]','$_POST[culture]','$_POST[gender]')";
>>     printf("-- %s --\n",$isql);
>>     $results = pg_query($isql);
>>     ?>
>>     <form method="post" action="<? echo $PHP_SELF?>">
>>       <input type="Submit" name="action" value="commit">
>>       <input type="Submit" name="action" value="rollback">
>>     </form>
>>     <?
>>   }
>>   else if(!$_POST[action]) {
>>   ?>
>>     <form method="post" action="<? echo $PHP_SELF?>">
>>       Diety:<input type="text" name="diety"><br>
>>       Culture:<input type="text" name="culture"><br>
>>       Gender:<input type="text" name="gender"><br>
>>       <input type="Submit" name="submit" value="enter">
>>     </form>
>>     <?
>>   }
>>   else {
>>     if($_POST[action] == 'commit') {
>>       echo "let me see";
>>       $act = pg_query("commit");
>>     }
>>     else {
>>       $act = pg_query("rollback");
>>       }
>>   }  //end if $_POST[submit]
>> ?>
>> </body>
>> </html>
>> ---------------------------(end of
>> broadcast)---------------------------
>> TIP 8: explain analyze is your friend
>
>


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings




^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.0] Re: [0.2] getting transactions to work
@ 2004-07-30 16:05  reiner peterke <zedaardv@drizzle.com>
  parent: Rod K <rod@23net.net>
  0 siblings, 1 reply; 18+ messages in thread

From: reiner peterke @ 2004-07-30 16:05 UTC (permalink / raw)
  To: Rod K <rod@23net.net>; +Cc: pgsql-php

i'm trying to test an idea.  i know what i sent doesn't do much, but i 
try out ideas before i go too far to make sure i understand what i 
think i do
in my 'real life'  i work with oracle.  i like the idea of explicitly 
telling the database when i'm done.  i want to be able to trap errors 
and rollback if necessary.  also to give someone the choice of saving 
the work or not.  i know there are things i can do to create the 
similar effect,
create the sql, then when i'm ready submit it to the database.

i guess i'm trying to test the limits right now!

thanks for the input.

r

On 30 jul 2004, at 17.11, Rod K wrote:

> You can find many resources to explain their purpose better than I can 
> do here.
>
> To be honest, I can't see what you are trying to accomplish in your 
> script.  If it's validation you should be using session variables to 
> store the input AND echoing what was inputed on the validation page.
>
> reiner peterke wrote:
>
>> this is meant in all honesty,
>>
>> then whats the point?!
>>
>> ok, let me put it this way.  is there no way to implement pages using 
>> transactions?
>> otherwise it seems to kind of defeat the purpose of them.
>>
>> r
>> On 30 jul 2004, at 16.57, Rod K wrote:
>>
>>> You are correct.  You cannot have a transaction span multiple 
>>> pages/scripts.
>>>
>>> reiner peterke wrote:
>>>
>>>> there seems to be very little info around on actually using 
>>>> transactions with postgres.  i've tried to create a page that will 
>>>> take input from a form and insert it into my database.  it works if 
>>>> i just do it without transactions but when i try to use with the 
>>>> begin and commit sections of code, it doesn't update the data base. 
>>>>  i'm guessing it is doing a rollback when my page loads itself 
>>>> again.  can anyone help me out here ?
>>>>
>>>> thanks
>>>>
>>>> r
>>>>
>>>> code below
>>>>
>>>> <html>
>>>> <head>
>>>> <submitle>those eyes</submitle>
>>>> </head>
>>>> <body>
>>>>   <?
>>>>   $conn = pg_connect("dbname=entish user=postgres");
>>>>     if(!$conn)
>>>>     {
>>>>       print "not for the chocolate";
>>>>       exit;
>>>>     }
>>>>   if ($_POST[submit])  {
>>>>
>>>>     $begin = pg_query("begin");
>>>>     $isql = "insert into diety(diety,culture,gender)
>>>>               values 
>>>> ('$_POST[diety]','$_POST[culture]','$_POST[gender]')";
>>>>     printf("-- %s --\n",$isql);
>>>>     $results = pg_query($isql);
>>>>     ?>
>>>>     <form method="post" action="<? echo $PHP_SELF?>">
>>>>       <input type="Submit" name="action" value="commit">
>>>>       <input type="Submit" name="action" value="rollback">
>>>>     </form>
>>>>     <?
>>>>   }
>>>>   else if(!$_POST[action]) {
>>>>   ?>
>>>>     <form method="post" action="<? echo $PHP_SELF?>">
>>>>       Diety:<input type="text" name="diety"><br>
>>>>       Culture:<input type="text" name="culture"><br>
>>>>       Gender:<input type="text" name="gender"><br>
>>>>       <input type="Submit" name="submit" value="enter">
>>>>     </form>
>>>>     <?
>>>>   }
>>>>   else {
>>>>     if($_POST[action] == 'commit') {
>>>>       echo "let me see";
>>>>       $act = pg_query("commit");
>>>>     }
>>>>     else {
>>>>       $act = pg_query("rollback");
>>>>       }
>>>>   }  //end if $_POST[submit]
>>>> ?>
>>>> </body>
>>>> </html>
>>>> ---------------------------(end of 
>>>> broadcast)---------------------------
>>>> TIP 8: explain analyze is your friend
>>>
>>>
>>>
>>
>
>
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
>               http://www.postgresql.org/docs/faqs/FAQ.html
>




^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.2] getting transactions to work
@ 2004-07-30 16:08  reiner peterke <zedaardv@drizzle.com>
  parent: bruce <bedouglas@earthlink.net>
  1 sibling, 2 replies; 18+ messages in thread

From: reiner peterke @ 2004-07-30 16:08 UTC (permalink / raw)
  To: bedouglas@earthlink.net; +Cc: pgsql-php; 'Rod K' <rod@23net.net>

well i've read about this thing called persistent connection,
i think it is supposed to exist in mysql also.  the idea sound like 
what i want. i've tried it but i didn't get any different results.  but 
then i'm not convinced i did it right either.

r

On 30 jul 2004, at 17.21, bruce wrote:

> if psgres works as mysql.... you should be able to do it...
>
> but the issue appears to be that the connection you establish with the 
> db in
> one page, is not available once you shut the page down.
>
> within mysql, there appears to be a mysqli group of functions that are 
> setup
> to accommodate transactions across multiple pages... i would 
> imagine/hope
> that the same sort of functionality is available for posgres....
>
> i'm getting close to needing the same functionality with mysql, and i'm
> betting/hoping like hell that what i've just described is how mysql/php
> works...
>
> -bruce
>
>
> -----Original Message-----
> From: pgsql-php-owner@postgresql.org
> [mailto:pgsql-php-owner@postgresql.org]On Behalf Of reiner peterke
> Sent: Friday, July 30, 2004 8:04 AM
> To: Rod K
> Cc: pgsql-php@postgresql.org
> Subject: Re: [0.2] [PHP] getting transactions to work
>
>
> this is meant in all honesty,
>
> then whats the point?!
>
> ok, let me put it this way.  is there no way to implement pages using
> transactions?
> otherwise it seems to kind of defeat the purpose of them.
>
> r
> On 30 jul 2004, at 16.57, Rod K wrote:
>
>> You are correct.  You cannot have a transaction span multiple
>> pages/scripts.
>>
>> reiner peterke wrote:
>>
>>> there seems to be very little info around on actually using
>>> transactions with postgres.  i've tried to create a page that will
>>> take input from a form and insert it into my database.  it works if i
>>> just do it without transactions but when i try to use with the begin
>>> and commit sections of code, it doesn't update the data base.  i'm
>>> guessing it is doing a rollback when my page loads itself again.  can
>>> anyone help me out here ?
>>>
>>> thanks
>>>
>>> r
>>>
>>> code below
>>>
>>> <html>
>>> <head>
>>> <submitle>those eyes</submitle>
>>> </head>
>>> <body>
>>>   <?
>>>   $conn = pg_connect("dbname=entish user=postgres");
>>>     if(!$conn)
>>>     {
>>>       print "not for the chocolate";
>>>       exit;
>>>     }
>>>   if ($_POST[submit])  {
>>>
>>>     $begin = pg_query("begin");
>>>     $isql = "insert into diety(diety,culture,gender)
>>>               values
>>> ('$_POST[diety]','$_POST[culture]','$_POST[gender]')";
>>>     printf("-- %s --\n",$isql);
>>>     $results = pg_query($isql);
>>>     ?>
>>>     <form method="post" action="<? echo $PHP_SELF?>">
>>>       <input type="Submit" name="action" value="commit">
>>>       <input type="Submit" name="action" value="rollback">
>>>     </form>
>>>     <?
>>>   }
>>>   else if(!$_POST[action]) {
>>>   ?>
>>>     <form method="post" action="<? echo $PHP_SELF?>">
>>>       Diety:<input type="text" name="diety"><br>
>>>       Culture:<input type="text" name="culture"><br>
>>>       Gender:<input type="text" name="gender"><br>
>>>       <input type="Submit" name="submit" value="enter">
>>>     </form>
>>>     <?
>>>   }
>>>   else {
>>>     if($_POST[action] == 'commit') {
>>>       echo "let me see";
>>>       $act = pg_query("commit");
>>>     }
>>>     else {
>>>       $act = pg_query("rollback");
>>>       }
>>>   }  //end if $_POST[submit]
>>> ?>
>>> </body>
>>> </html>
>>> ---------------------------(end of
>>> broadcast)---------------------------
>>> TIP 8: explain analyze is your friend
>>
>>
>
>
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>
>
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if 
> your
>       joining column's datatypes do not match
>




^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.0] Re: [0.2] getting transactions to work
@ 2004-07-30 16:13  Rod K <rod@23net.net>
  parent: reiner peterke <zedaardv@drizzle.com>
  1 sibling, 1 reply; 18+ messages in thread

From: Rod K @ 2004-07-30 16:13 UTC (permalink / raw)
  To: reiner peterke <zedaardv@drizzle.com>; +Cc: bedouglas@earthlink.net; pgsql-php

No, persistent connections will not work either.

reiner peterke wrote:

> well i've read about this thing called persistent connection,
> i think it is supposed to exist in mysql also.  the idea sound like 
> what i want. i've tried it but i didn't get any different results.  
> but then i'm not convinced i did it right either.
>
> r
>
> On 30 jul 2004, at 17.21, bruce wrote:
>
>> if psgres works as mysql.... you should be able to do it...
>>
>> but the issue appears to be that the connection you establish with 
>> the db in
>> one page, is not available once you shut the page down.
>>
>> within mysql, there appears to be a mysqli group of functions that 
>> are setup
>> to accommodate transactions across multiple pages... i would 
>> imagine/hope
>> that the same sort of functionality is available for posgres....
>>
>> i'm getting close to needing the same functionality with mysql, and i'm
>> betting/hoping like hell that what i've just described is how mysql/php
>> works...
>>
>> -bruce
>>
>>
>> -----Original Message-----
>> From: pgsql-php-owner@postgresql.org
>> [mailto:pgsql-php-owner@postgresql.org]On Behalf Of reiner peterke
>> Sent: Friday, July 30, 2004 8:04 AM
>> To: Rod K
>> Cc: pgsql-php@postgresql.org
>> Subject: Re: [0.2] [PHP] getting transactions to work
>>
>>
>> this is meant in all honesty,
>>
>> then whats the point?!
>>
>> ok, let me put it this way.  is there no way to implement pages using
>> transactions?
>> otherwise it seems to kind of defeat the purpose of them.
>>
>> r
>> On 30 jul 2004, at 16.57, Rod K wrote:
>>
>>> You are correct.  You cannot have a transaction span multiple
>>> pages/scripts.
>>>
>>> reiner peterke wrote:
>>>
>>>> there seems to be very little info around on actually using
>>>> transactions with postgres.  i've tried to create a page that will
>>>> take input from a form and insert it into my database.  it works if i
>>>> just do it without transactions but when i try to use with the begin
>>>> and commit sections of code, it doesn't update the data base.  i'm
>>>> guessing it is doing a rollback when my page loads itself again.  can
>>>> anyone help me out here ?
>>>>
>>>> thanks
>>>>
>>>> r
>>>>
>>>> code below
>>>>
>>>> <html>
>>>> <head>
>>>> <submitle>those eyes</submitle>
>>>> </head>
>>>> <body>
>>>>   <?
>>>>   $conn = pg_connect("dbname=entish user=postgres");
>>>>     if(!$conn)
>>>>     {
>>>>       print "not for the chocolate";
>>>>       exit;
>>>>     }
>>>>   if ($_POST[submit])  {
>>>>
>>>>     $begin = pg_query("begin");
>>>>     $isql = "insert into diety(diety,culture,gender)
>>>>               values
>>>> ('$_POST[diety]','$_POST[culture]','$_POST[gender]')";
>>>>     printf("-- %s --\n",$isql);
>>>>     $results = pg_query($isql);
>>>>     ?>
>>>>     <form method="post" action="<? echo $PHP_SELF?>">
>>>>       <input type="Submit" name="action" value="commit">
>>>>       <input type="Submit" name="action" value="rollback">
>>>>     </form>
>>>>     <?
>>>>   }
>>>>   else if(!$_POST[action]) {
>>>>   ?>
>>>>     <form method="post" action="<? echo $PHP_SELF?>">
>>>>       Diety:<input type="text" name="diety"><br>
>>>>       Culture:<input type="text" name="culture"><br>
>>>>       Gender:<input type="text" name="gender"><br>
>>>>       <input type="Submit" name="submit" value="enter">
>>>>     </form>
>>>>     <?
>>>>   }
>>>>   else {
>>>>     if($_POST[action] == 'commit') {
>>>>       echo "let me see";
>>>>       $act = pg_query("commit");
>>>>     }
>>>>     else {
>>>>       $act = pg_query("rollback");
>>>>       }
>>>>   }  //end if $_POST[submit]
>>>> ?>
>>>> </body>
>>>> </html>
>>>> ---------------------------(end of
>>>> broadcast)---------------------------
>>>> TIP 8: explain analyze is your friend
>>>
>>>
>>>
>>
>>
>> ---------------------------(end of broadcast)---------------------------
>> TIP 7: don't forget to increase your free space map settings
>>
>>
>> ---------------------------(end of broadcast)---------------------------
>> TIP 9: the planner will ignore your desire to choose an index scan if 
>> your
>>       joining column's datatypes do not match
>>
>




^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.0] Re: [0.2] getting transactions to work
@ 2004-07-30 16:26  reiner peterke <zedaardv@drizzle.com>
  parent: Rod K <rod@23net.net>
  0 siblings, 1 reply; 18+ messages in thread

From: reiner peterke @ 2004-07-30 16:26 UTC (permalink / raw)
  To: Rod K <rod@23net.net>; +Cc: pgsql-php; bedouglas@earthlink.net

ok,

thanks


On 30 jul 2004, at 18.13, Rod K wrote:

> No, persistent connections will not work either.
>
> reiner peterke wrote:
>
>> well i've read about this thing called persistent connection,
>> i think it is supposed to exist in mysql also.  the idea sound like 
>> what i want. i've tried it but i didn't get any different results.  
>> but then i'm not convinced i did it right either.
>>
>> r
>>
>> On 30 jul 2004, at 17.21, bruce wrote:
>>
>>> if psgres works as mysql.... you should be able to do it...
>>>
>>> but the issue appears to be that the connection you establish with 
>>> the db in
>>> one page, is not available once you shut the page down.
>>>
>>> within mysql, there appears to be a mysqli group of functions that 
>>> are setup
>>> to accommodate transactions across multiple pages... i would 
>>> imagine/hope
>>> that the same sort of functionality is available for posgres....
>>>
>>> i'm getting close to needing the same functionality with mysql, and 
>>> i'm
>>> betting/hoping like hell that what i've just described is how 
>>> mysql/php
>>> works...
>>>
>>> -bruce
>>>
>>>
>>> -----Original Message-----
>>> From: pgsql-php-owner@postgresql.org
>>> [mailto:pgsql-php-owner@postgresql.org]On Behalf Of reiner peterke
>>> Sent: Friday, July 30, 2004 8:04 AM
>>> To: Rod K
>>> Cc: pgsql-php@postgresql.org
>>> Subject: Re: [0.2] [PHP] getting transactions to work
>>>
>>>
>>> this is meant in all honesty,
>>>
>>> then whats the point?!
>>>
>>> ok, let me put it this way.  is there no way to implement pages using
>>> transactions?
>>> otherwise it seems to kind of defeat the purpose of them.
>>>
>>> r
>>> On 30 jul 2004, at 16.57, Rod K wrote:
>>>
>>>> You are correct.  You cannot have a transaction span multiple
>>>> pages/scripts.
>>>>
>>>> reiner peterke wrote:
>>>>
>>>>> there seems to be very little info around on actually using
>>>>> transactions with postgres.  i've tried to create a page that will
>>>>> take input from a form and insert it into my database.  it works 
>>>>> if i
>>>>> just do it without transactions but when i try to use with the 
>>>>> begin
>>>>> and commit sections of code, it doesn't update the data base.  i'm
>>>>> guessing it is doing a rollback when my page loads itself again.  
>>>>> can
>>>>> anyone help me out here ?
>>>>>
>>>>> thanks
>>>>>
>>>>> r
>>>>>
>>>>> code below
>>>>>
>>>>> <html>
>>>>> <head>
>>>>> <submitle>those eyes</submitle>
>>>>> </head>
>>>>> <body>
>>>>>   <?
>>>>>   $conn = pg_connect("dbname=entish user=postgres");
>>>>>     if(!$conn)
>>>>>     {
>>>>>       print "not for the chocolate";
>>>>>       exit;
>>>>>     }
>>>>>   if ($_POST[submit])  {
>>>>>
>>>>>     $begin = pg_query("begin");
>>>>>     $isql = "insert into diety(diety,culture,gender)
>>>>>               values
>>>>> ('$_POST[diety]','$_POST[culture]','$_POST[gender]')";
>>>>>     printf("-- %s --\n",$isql);
>>>>>     $results = pg_query($isql);
>>>>>     ?>
>>>>>     <form method="post" action="<? echo $PHP_SELF?>">
>>>>>       <input type="Submit" name="action" value="commit">
>>>>>       <input type="Submit" name="action" value="rollback">
>>>>>     </form>
>>>>>     <?
>>>>>   }
>>>>>   else if(!$_POST[action]) {
>>>>>   ?>
>>>>>     <form method="post" action="<? echo $PHP_SELF?>">
>>>>>       Diety:<input type="text" name="diety"><br>
>>>>>       Culture:<input type="text" name="culture"><br>
>>>>>       Gender:<input type="text" name="gender"><br>
>>>>>       <input type="Submit" name="submit" value="enter">
>>>>>     </form>
>>>>>     <?
>>>>>   }
>>>>>   else {
>>>>>     if($_POST[action] == 'commit') {
>>>>>       echo "let me see";
>>>>>       $act = pg_query("commit");
>>>>>     }
>>>>>     else {
>>>>>       $act = pg_query("rollback");
>>>>>       }
>>>>>   }  //end if $_POST[submit]
>>>>> ?>
>>>>> </body>
>>>>> </html>
>>>>> ---------------------------(end of
>>>>> broadcast)---------------------------
>>>>> TIP 8: explain analyze is your friend
>>>>
>>>>
>>>>
>>>
>>>
>>> ---------------------------(end of 
>>> broadcast)---------------------------
>>> TIP 7: don't forget to increase your free space map settings
>>>
>>>
>>> ---------------------------(end of 
>>> broadcast)---------------------------
>>> TIP 9: the planner will ignore your desire to choose an index scan 
>>> if your
>>>       joining column's datatypes do not match
>>>
>>
>
>
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
>               http://archives.postgresql.org
>




^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.2] getting transactions to work
@ 2004-07-30 16:31  Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  parent: bruce <bedouglas@earthlink.net>
  1 sibling, 0 replies; 18+ messages in thread

From: Christopher Kings-Lynne @ 2004-07-30 16:31 UTC (permalink / raw)
  To: bedouglas@earthlink.net; +Cc: reiner peterke <zedaardv@drizzle.com>; Rod K <rod@23net.net>; pgsql-php

> i'm getting close to needing the same functionality with mysql, and i'm
> betting/hoping like hell that what i've just described is how mysql/php
> works...

Err, it's not.

Chris




^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.0] Re: [0.2] getting transactions to work
@ 2004-07-30 16:32  Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  parent: reiner peterke <zedaardv@drizzle.com>
  0 siblings, 1 reply; 18+ messages in thread

From: Christopher Kings-Lynne @ 2004-07-30 16:32 UTC (permalink / raw)
  To: reiner peterke <zedaardv@drizzle.com>; +Cc: Rod K <rod@23net.net>; pgsql-php

> i'm trying to test an idea.  i know what i sent doesn't do much, but i 
> try out ideas before i go too far to make sure i understand what i think 
> i do
> in my 'real life'  i work with oracle.  i like the idea of explicitly 
> telling the database when i'm done.  i want to be able to trap errors 
> and rollback if necessary.  also to give someone the choice of saving 
> the work or not.  i know there are things i can do to create the similar 
> effect,
> create the sql, then when i'm ready submit it to the database.

Oracle doesn't do what you want either.  I'm afraid you have a 
fundamental misunderstanding of how the HTTP process works.

Chris




^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.0] Re: [0.2] getting transactions to work
@ 2004-07-30 16:35  bruce <bedouglas@earthlink.net>
  parent: reiner peterke <zedaardv@drizzle.com>
  0 siblings, 0 replies; 18+ messages in thread

From: bruce @ 2004-07-30 16:35 UTC (permalink / raw)
  To: 'reiner peterke' <zedaardv@drizzle.com>; 'Rod K' <rod@23net.net>; +Cc: pgsql-php

the idea behind persistent connections is to simply allow you to open a
connection, that is persistent, ie, it's there for other db functions to use
and that the app doesn't go through the process of opening up a new
connection. with a persistent connection, the app essentially looks to see
if an existing connection has already been open that's available for use.

-bruce


-----Original Message-----
From: reiner peterke [mailto:zedaardv@drizzle.com]
Sent: Friday, July 30, 2004 9:27 AM
To: Rod K
Cc: pgsql-php@postgresql.org; bedouglas@earthlink.net
Subject: Re: [0.0] Re: [0.2] [PHP] getting transactions to work


ok,

thanks


On 30 jul 2004, at 18.13, Rod K wrote:

> No, persistent connections will not work either.
>
> reiner peterke wrote:
>
>> well i've read about this thing called persistent connection,
>> i think it is supposed to exist in mysql also.  the idea sound like
>> what i want. i've tried it but i didn't get any different results.
>> but then i'm not convinced i did it right either.
>>
>> r
>>
>> On 30 jul 2004, at 17.21, bruce wrote:
>>
>>> if psgres works as mysql.... you should be able to do it...
>>>
>>> but the issue appears to be that the connection you establish with
>>> the db in
>>> one page, is not available once you shut the page down.
>>>
>>> within mysql, there appears to be a mysqli group of functions that
>>> are setup
>>> to accommodate transactions across multiple pages... i would
>>> imagine/hope
>>> that the same sort of functionality is available for posgres....
>>>
>>> i'm getting close to needing the same functionality with mysql, and
>>> i'm
>>> betting/hoping like hell that what i've just described is how
>>> mysql/php
>>> works...
>>>
>>> -bruce
>>>
>>>
>>> -----Original Message-----
>>> From: pgsql-php-owner@postgresql.org
>>> [mailto:pgsql-php-owner@postgresql.org]On Behalf Of reiner peterke
>>> Sent: Friday, July 30, 2004 8:04 AM
>>> To: Rod K
>>> Cc: pgsql-php@postgresql.org
>>> Subject: Re: [0.2] [PHP] getting transactions to work
>>>
>>>
>>> this is meant in all honesty,
>>>
>>> then whats the point?!
>>>
>>> ok, let me put it this way.  is there no way to implement pages using
>>> transactions?
>>> otherwise it seems to kind of defeat the purpose of them.
>>>
>>> r
>>> On 30 jul 2004, at 16.57, Rod K wrote:
>>>
>>>> You are correct.  You cannot have a transaction span multiple
>>>> pages/scripts.
>>>>
>>>> reiner peterke wrote:
>>>>
>>>>> there seems to be very little info around on actually using
>>>>> transactions with postgres.  i've tried to create a page that will
>>>>> take input from a form and insert it into my database.  it works
>>>>> if i
>>>>> just do it without transactions but when i try to use with the
>>>>> begin
>>>>> and commit sections of code, it doesn't update the data base.  i'm
>>>>> guessing it is doing a rollback when my page loads itself again.
>>>>> can
>>>>> anyone help me out here ?
>>>>>
>>>>> thanks
>>>>>
>>>>> r
>>>>>
>>>>> code below
>>>>>
>>>>> <html>
>>>>> <head>
>>>>> <submitle>those eyes</submitle>
>>>>> </head>
>>>>> <body>
>>>>>   <?
>>>>>   $conn = pg_connect("dbname=entish user=postgres");
>>>>>     if(!$conn)
>>>>>     {
>>>>>       print "not for the chocolate";
>>>>>       exit;
>>>>>     }
>>>>>   if ($_POST[submit])  {
>>>>>
>>>>>     $begin = pg_query("begin");
>>>>>     $isql = "insert into diety(diety,culture,gender)
>>>>>               values
>>>>> ('$_POST[diety]','$_POST[culture]','$_POST[gender]')";
>>>>>     printf("-- %s --\n",$isql);
>>>>>     $results = pg_query($isql);
>>>>>     ?>
>>>>>     <form method="post" action="<? echo $PHP_SELF?>">
>>>>>       <input type="Submit" name="action" value="commit">
>>>>>       <input type="Submit" name="action" value="rollback">
>>>>>     </form>
>>>>>     <?
>>>>>   }
>>>>>   else if(!$_POST[action]) {
>>>>>   ?>
>>>>>     <form method="post" action="<? echo $PHP_SELF?>">
>>>>>       Diety:<input type="text" name="diety"><br>
>>>>>       Culture:<input type="text" name="culture"><br>
>>>>>       Gender:<input type="text" name="gender"><br>
>>>>>       <input type="Submit" name="submit" value="enter">
>>>>>     </form>
>>>>>     <?
>>>>>   }
>>>>>   else {
>>>>>     if($_POST[action] == 'commit') {
>>>>>       echo "let me see";
>>>>>       $act = pg_query("commit");
>>>>>     }
>>>>>     else {
>>>>>       $act = pg_query("rollback");
>>>>>       }
>>>>>   }  //end if $_POST[submit]
>>>>> ?>
>>>>> </body>
>>>>> </html>
>>>>> ---------------------------(end of
>>>>> broadcast)---------------------------
>>>>> TIP 8: explain analyze is your friend
>>>>
>>>>
>>>>
>>>
>>>
>>> ---------------------------(end of
>>> broadcast)---------------------------
>>> TIP 7: don't forget to increase your free space map settings
>>>
>>>
>>> ---------------------------(end of
>>> broadcast)---------------------------
>>> TIP 9: the planner will ignore your desire to choose an index scan
>>> if your
>>>       joining column's datatypes do not match
>>>
>>
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
>               http://archives.postgresql.org
>




^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.0] Re: [0.2] getting transactions to work
@ 2004-07-30 16:57  reiner peterke <zedaardv@drizzle.com>
  parent: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  0 siblings, 1 reply; 18+ messages in thread

From: reiner peterke @ 2004-07-30 16:57 UTC (permalink / raw)
  To: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; +Cc: pgsql-php@postgresql.org, Rod K <rod@23net.net>

i never said oracle did do that.
i don 't have so much experience working with databases and web pages
i do not have any understanding or misunderstanding.  i am trying to 
learn how it does work here.  to my mind it should be able to work 
within a web page.  maybe you could be so kind as to explain to me why 
it does not work.

r

On 30 jul 2004, at 18.32, Christopher Kings-Lynne wrote:

>> i'm trying to test an idea.  i know what i sent doesn't do much, but 
>> i try out ideas before i go too far to make sure i understand what i 
>> think i do
>> in my 'real life'  i work with oracle.  i like the idea of explicitly 
>> telling the database when i'm done.  i want to be able to trap errors 
>> and rollback if necessary.  also to give someone the choice of saving 
>> the work or not.  i know there are things i can do to create the 
>> similar effect,
>> create the sql, then when i'm ready submit it to the database.
>
> Oracle doesn't do what you want either.  I'm afraid you have a 
> fundamental misunderstanding of how the HTTP process works.
>
> Chris
>
>
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to 
> majordomo@postgresql.org
>




^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.0] Re: [0.2] getting transactions to work
@ 2004-07-30 18:48  Thom Dyson <TDyson@sybex.com>
  parent: reiner peterke <zedaardv@drizzle.com>
  0 siblings, 1 reply; 18+ messages in thread

From: Thom Dyson @ 2004-07-30 18:48 UTC (permalink / raw)
  To: pgsql-php





Under PHP (or any cgi type of process), postgres sessions cannot cross
multiple html pages.  This is neither a flaw in PHP nor postgres; it is a
fact that is database and language independent.

Each page submission, that is each php invocation, starts a session that is
closed when the php script is done. the stateless nature of HTTP is at the
heart of this.  A web server sees each page request as a stand alone event,
with no relationship to any other request.  The ability to do "sessions" is
the work around to this.

So, if you need to carry information from one web page to another , you
either have to write hidden values to the html page (a bad idea on sorts of
levels) or use session variables to that PHP/postgres can retain
information.

Thom Dyson
Director of Information Services
Sybex, Inc.



pgsql-php-owner@postgresql.org wrote on 07/30/2004 09:57:53 AM:

> i never said oracle did do that.
> i don 't have so much experience working with databases and web pages
> i do not have any understanding or misunderstanding.  i am trying to
> learn how it does work here.  to my mind it should be able to work
> within a web page.  maybe you could be so kind as to explain to me why
> it does not work.

> r




^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.2] getting transactions to work
@ 2004-07-30 19:54  Frank Finner <postgresql@finner.de>
  parent: Rod K <rod@23net.net>
  1 sibling, 0 replies; 18+ messages in thread

From: Frank Finner @ 2004-07-30 19:54 UTC (permalink / raw)
  To: zedaardv@drizzle.com; +Cc: pgsql-php

You could have a transaction span multiple pages (not scripts), if you keep the
script in memory and use different parts of it with different templates for
different pages. This is possible using FastCGI (http://www.fastcgi.com). I
do this with Perl, occasionally with C, but I did not have spare time to try it
with PHP, although it should work, if you use PHP like a FastCGI CGI script, and
not a one-script-per-page technique.

Of course there are some drawbacks like necessity to always initialise
variables very carefully, possibility of noticeable memory leaks and strange
cacheing effects. In fact with FastCGI you create a persistent server
application connected to your webserver, not just a volatile script.

Regards, Frank.


On Fri, 30 Jul 2004 10:57:47 -0400 Rod K <rod@23net.net> sat down, thought long
and then wrote:

> You are correct.  You cannot have a transaction span multiple pages/scripts.
> 
> reiner peterke wrote:
> 
> > there seems to be very little info around on actually using 
> > transactions with postgres.  i've tried to create a page that will 
> > take input from a form and insert it into my database.  it works if i 
> > just do it without transactions but when i try to use with the begin 
> > and commit sections of code, it doesn't update the data base.  i'm 
> > guessing it is doing a rollback when my page loads itself again.  can 
> > anyone help me out here ?
> >
> > thanks
> >


-- 
Frank Finner

Invenius - Solutions in Linux
Köpfchenstraße 36
57072 Siegen
Telefon: 0271 231 8606    Mail: frank.finner@invenius.org
Telefax: 0271 231 8608    Web:  http://www.invenius.org
Key fingerprint = 6A60 FA85 F670 4FC3 CD7C  CED5 4F4C 72B1 54AC 165E


^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.0] Re: [0.2] getting transactions to work
@ 2004-07-31 09:15  reiner peterke <zedaardv@drizzle.com>
  parent: Thom Dyson <TDyson@sybex.com>
  0 siblings, 0 replies; 18+ messages in thread

From: reiner peterke @ 2004-07-31 09:15 UTC (permalink / raw)
  To: Thom Dyson <TDyson@sybex.com>; +Cc: pgsql-php

thanks for all the feed back
at least now i have a better idea on how to proceede.

r
On 30 jul 2004, at 20.48, Thom Dyson wrote:

>
>
>
>
> Under PHP (or any cgi type of process), postgres sessions cannot cross
> multiple html pages.  This is neither a flaw in PHP nor postgres; it 
> is a
> fact that is database and language independent.
>
> Each page submission, that is each php invocation, starts a session 
> that is
> closed when the php script is done. the stateless nature of HTTP is at 
> the
> heart of this.  A web server sees each page request as a stand alone 
> event,
> with no relationship to any other request.  The ability to do 
> "sessions" is
> the work around to this.
>
> So, if you need to carry information from one web page to another , you
> either have to write hidden values to the html page (a bad idea on 
> sorts of
> levels) or use session variables to that PHP/postgres can retain
> information.
>
> Thom Dyson
> Director of Information Services
> Sybex, Inc.
>
>
>
> pgsql-php-owner@postgresql.org wrote on 07/30/2004 09:57:53 AM:
>
>> i never said oracle did do that.
>> i don 't have so much experience working with databases and web pages
>> i do not have any understanding or misunderstanding.  i am trying to
>> learn how it does work here.  to my mind it should be able to work
>> within a web page.  maybe you could be so kind as to explain to me why
>> it does not work.
>
>> r
>
>
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to 
> majordomo@postgresql.org
>




^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.2] getting transactions to work
@ 2004-08-06 10:02  Marco Colombo <marco@esi.it>
  parent: reiner peterke <zedaardv@drizzle.com>
  1 sibling, 1 reply; 18+ messages in thread

From: Marco Colombo @ 2004-08-06 10:02 UTC (permalink / raw)
  To: reiner peterke <zedaardv@drizzle.com>; +Cc: pgsql-php

reiner peterke wrote:
> well i've read about this thing called persistent connection,
> i think it is supposed to exist in mysql also.  the idea sound like what 
> i want. i've tried it but i didn't get any different results.  but then 
> i'm not convinced i did it right either.

You have to face the fact that HTTP is _stateless_. Any common HTTP server
will obey to that, thus destroying any resource related to the request it
just served, _or_ making it appear as if it was destroyed. You really need to
think hard of the implications here.

Persistent connections are no exception: they are just a way to boost
perfermance, but there should be no visible difference at application
level. That is, you should be able to change pg_connect()'s with
pg_pconnect()'s (and vice versa) without changing anything else in your
PHP scripts. Persistent connections add _no_ extra functionality to your
PHP application.

Transactions exist at SQL session level. A "session" is inherently
statefull, and will be destroyed (or made appear as destroyed) at the end
for each HTTP request, because it _has_ to appear stateless. The request
for the 'next' page may be served by a different process, or a even a
different host, so no state can be shared. There's simply no way you can
control this.

Sessions/cookies alone won't let you use transactions, they'll just
emulate them. You can delay the transaction till the final page, but
it's just not the same.

Of course, you can write your own HTTP server (there are simple-to-use Perl
or Python modules to do that) that deliberately fails to adhere to the
HTTP model, and keeps some state. If you control all the environment, that
may even work.

One possible solution is to write proxy application (a server), which talks
on one side to the SQL db and on the other to the PHP frontend.

.TM.
-- 
       ____/  ____/   /
      /      /       /			Marco Colombo
     ___/  ___  /   /		      Technical Manager
    /          /   /			 ESI s.r.l.
  _____/ _____/  _/		       Colombo@ESI.it



^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: [0.2] getting transactions to work
@ 2004-08-06 17:56  bruce <bedouglas@earthlink.net>
  parent: Marco Colombo <marco@esi.it>
  0 siblings, 0 replies; 18+ messages in thread

From: bruce @ 2004-08-06 17:56 UTC (permalink / raw)
  To: 'Marco Colombo' <marco@esi.it>; 'reiner peterke' <zedaardv@drizzle.com>; +Cc: pgsql-php

actually, mod_perl is "supposed" to allow a web app to be written such that
the db connections are resident in memory, and therefore, available to
multiple pages across the web app for a given session....

i haven't tried/tested this, but i've heard that it is supposed to be
possible.

i've had an email exchange with one of the mysql developers who states that
this kind of functionality wil be built into the mysql app and should be
available within the next 3-4 months...

regards,



-----Original Message-----
From: pgsql-php-owner@postgresql.org
[mailto:pgsql-php-owner@postgresql.org]On Behalf Of Marco Colombo
Sent: Friday, August 06, 2004 3:02 AM
To: reiner peterke
Cc: pgsql-php@postgresql.org
Subject: Re: [0.2] [PHP] getting transactions to work


reiner peterke wrote:
> well i've read about this thing called persistent connection,
> i think it is supposed to exist in mysql also.  the idea sound like what
> i want. i've tried it but i didn't get any different results.  but then
> i'm not convinced i did it right either.

You have to face the fact that HTTP is _stateless_. Any common HTTP server
will obey to that, thus destroying any resource related to the request it
just served, _or_ making it appear as if it was destroyed. You really need
to
think hard of the implications here.

Persistent connections are no exception: they are just a way to boost
perfermance, but there should be no visible difference at application
level. That is, you should be able to change pg_connect()'s with
pg_pconnect()'s (and vice versa) without changing anything else in your
PHP scripts. Persistent connections add _no_ extra functionality to your
PHP application.

Transactions exist at SQL session level. A "session" is inherently
statefull, and will be destroyed (or made appear as destroyed) at the end
for each HTTP request, because it _has_ to appear stateless. The request
for the 'next' page may be served by a different process, or a even a
different host, so no state can be shared. There's simply no way you can
control this.

Sessions/cookies alone won't let you use transactions, they'll just
emulate them. You can delay the transaction till the final page, but
it's just not the same.

Of course, you can write your own HTTP server (there are simple-to-use Perl
or Python modules to do that) that deliberately fails to adhere to the
HTTP model, and keeps some state. If you control all the environment, that
may even work.

One possible solution is to write proxy application (a server), which talks
on one side to the SQL db and on the other to the PHP frontend.

.TM.
--
       ____/  ____/   /
      /      /       /			Marco Colombo
     ___/  ___  /   /		      Technical Manager
    /          /   /			 ESI s.r.l.
  _____/ _____/  _/		       Colombo@ESI.it

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster




^ permalink  raw  reply  [nested|flat] 18+ messages in thread


end of thread, other threads:[~2004-08-06 17:56 UTC | newest]

Thread overview: 18+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-07-30 14:53 getting transactions to work reiner peterke <zedaardv@drizzle.com>
2004-07-30 14:57 ` Rod K <rod@23net.net>
2004-07-30 15:03   ` reiner peterke <zedaardv@drizzle.com>
2004-07-30 15:11     ` Rod K <rod@23net.net>
2004-07-30 16:05       ` reiner peterke <zedaardv@drizzle.com>
2004-07-30 16:32         ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2004-07-30 16:57           ` reiner peterke <zedaardv@drizzle.com>
2004-07-30 18:48             ` Thom Dyson <TDyson@sybex.com>
2004-07-31 09:15               ` reiner peterke <zedaardv@drizzle.com>
2004-07-30 15:21     ` bruce <bedouglas@earthlink.net>
2004-07-30 16:08       ` reiner peterke <zedaardv@drizzle.com>
2004-07-30 16:13         ` Rod K <rod@23net.net>
2004-07-30 16:26           ` reiner peterke <zedaardv@drizzle.com>
2004-07-30 16:35             ` bruce <bedouglas@earthlink.net>
2004-08-06 10:02         ` Marco Colombo <marco@esi.it>
2004-08-06 17:56           ` bruce <bedouglas@earthlink.net>
2004-07-30 16:31       ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2004-07-30 19:54   ` Frank Finner <postgresql@finner.de>

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