X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 62A74310504 for ; Tue, 10 Jun 2003 08:51:30 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 59980-07 for ; Tue, 10 Jun 2003 05:51:19 -0300 (ADT) Received: from jive.SoftHome.net (jive.SoftHome.net [66.54.152.27]) by svr1.postgresql.org (Postfix) with SMTP id 23BB130F5F4 for ; Tue, 10 Jun 2003 05:07:47 -0300 (ADT) Received: (qmail 13522 invoked by uid 417); 10 Jun 2003 08:07:46 -0000 Received: from shunt-smtp-out-0 (HELO softhome.net) (172.16.3.12) by shunt-smtp-out-0 with SMTP; 10 Jun 2003 08:07:46 -0000 Received: from clairvo ([217.217.107.146]) (AUTH: LOGIN adriantineo@softhome.net) by softhome.net with esmtp; Tue, 10 Jun 2003 02:07:13 -0600 Message-ID: <000801c32f27$553013b0$926bd9d9@clairvo> From: "Adrian Tineo" To: "Michael Glaesemann" , pgsql-php@postgresql.org References: Subject: Re: Cleaning up aborted transactions Date: Tue, 10 Jun 2003 10:05:42 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Archive-Number: 200306/4 X-Sequence-Number: 2068 The correct way of working with transactions is to use: BEGIN ...sql commands COMMIT or ROLLBACK So I would use this for example: pg_connect($connection); pg_query($connection,"BEGIN;"); $insert="INSERT INTO table VALUES (2,7,5); $result=pg_query($connection,$insert); if(!$result){ pg_query($connection,"ROLLBACK"); //Something went wrong with the insert so we rollback and nothing changes in the db }else{ pg_query($connection,"COMMIT"); // If everything went all right, then we commit the changes } pg_close($connection); Of course, the interesting thing comes when you have several operations (inserts, deletes or updates) between begin and commit, this way either you make all the changes or make none, that's the cool thing about transactions. In each operation just check whether the result was valid or not. If ANY of them was invalid, rollback and none of the changes will take effect. I don't know if this answer your question... Adrian Tineo