On Fri, Jun 25, 1999 at 05:01:29PM +0100, Mario Jorge Nunes Filipe wrote:
> Thomas Reinke wrote:
> >
> > You have already started a transaction and haven't yet
> > finished it.
> >
> > E.g.
> >
> > psql template;
> > BEGIN;
> > BEGIN;
>
> Not that i don't believe you but i think that in my case that is a tid
> bit impossible. The error comes from a php script. On that script i open
> the connection, then i do a select and then the begin. So there isn't
> anyother begin. I've tryed to run an abort before that but it still
> doen't return a result, althoug there is no message error either.
>
> I really need help here, because i really need this thing working with
> transactions. Just in case here is the code:
>
> pg_Exec($conn, "abort");
> $result = @pg_Exec($conn, "begin");
> if (!$result);
> $msg ="sac-pcgra (2):".addslashes(pg_ErrorMessage($conn));
> $msg = chop($msg);
> echo "<script>alert(\"$msg\");history.go(-1)</script>";
> pg_Close($conn);
> exit;
> }
Here is some code from one of my projects (displays the top 15
speakers in a database of irc transactions). I don't bother to post
a COMMIT in this case because it is just a select. On another system,
I do get warning (not error) messages about not COMMITing transactions,
btw.
$pgconn = pg_connect("socket", "5432", "", "", "slashnet");
$result = pg_exec($pgconn, "BEGIN");
$result = pg_exec($pgconn, "DECLARE foo CURSOR FOR select nick, count(*) as tcoun
t from messages group by nick order by tcount desc");
$result = pg_exec($pgconn, "FETCH 15 IN foo");
$rows = pg_numrows($result);