Re: PREPARE -> EXECUTE Problem

Lists: pgsql-php
From: "F(dot)" <dev001(at)pas-world(dot)com>
To: pgsql-php(at)postgresql(dot)org
Subject: Re: PREPARE -> EXECUTE Problem
Date: 2009-01-15 11:43:30
Message-ID: 1232019811.9838.9.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: Postg토토 베이SQL : Postg토토 베이SQL 메일 링리스트 : 2009-01-15 이후 PGSQL-PHP 11:43

>Just ignore the default.
>Have you set up the table with SERIAL?
>if so this should work:

After some changes, for the moment seems the good choice.
But have a problem getting pdo->lastInsertId(), do not work in postgre
for me.

I am using this :
select currval('table_id_seq');

Any clear method?

--

--
Publicidad http://www.pas-world.com


From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-php(at)postgresql(dot)org
Subject: Re: PREPARE -> EXECUTE Problem
Date: 2009-01-18 00:48:24
Message-ID: gktu8o$f6fgktu8o$f6f$1@reversiblemaps.ath.cx@reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-php

On 2009-01-15, F. <dev001(at)pas-world(dot)com> wrote:
> >Just ignore the default.
> >Have you set up the table with SERIAL?
> >if so this should work:
>
> After some changes, for the moment seems the good choice.
> But have a problem getting pdo->lastInsertId(), do not work in postgre
> for me.
>
> I am using this :
> select currval('table_id_seq');
>

do this

select nextval('table_id_seq');

before you insert, and insert the value that gives.

this solves your other problem (use of DEFAULT) too, (or is that the
same problem)

another option is to use 'RETURNING id' when you insert

INSERT
INTO "mytable" ( "thatcolumn" )
VALUES ( 'whatever' )
RETURNING "id";

this needs PG >= 8.2