X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id AA682D1B554 for ; Mon, 6 Oct 2003 08:16:42 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 10049-06 for ; Mon, 6 Oct 2003 05:15:54 -0300 (ADT) Received: from smtp011.mail.yahoo.com (smtp011.mail.yahoo.com [216.136.173.31]) by svr1.postgresql.org (Postfix) with SMTP id 24BA4D1B4EA for ; Mon, 6 Oct 2003 05:15:52 -0300 (ADT) Received: from adsl24.226.axelero.hu (HELO loser2000) (sbaudry@195.228.226.24 with login) by smtp.mail.vip.sc5.yahoo.com with SMTP; 6 Oct 2003 08:15:53 -0000 Reply-To: From: "Sebastien Baudry" To: Subject: Re: How to manipulate a cursor returned by a PL/pgSQL in a PHP Date: Mon, 6 Oct 2003 10:17:51 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) In-Reply-To: <200310050921.47505.akopciuch@olympusproject.org> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/12 X-Sequence-Number: 2373 Hi. I finally found out how to fetch the cursor returned by a PostGreSQL functi= on in my PHP script. Here from the Postgres archives: http://archives.postgresql.org/pgsql-php/2= 002-11/msg00054.php This is the "head" of function: -------------- create or replace function match(refcursor,int8) returns=20 refcursor as ' DECLARE vid ALIAS FOR $2; vcursor ALIAS FOR $1; BEGIN (...) return vcursor; (...) -------------- =20 And this is php call: -------------- $conn =3D pg_pconnect ($conn_string); $qry =3D "BEGIN; SELECT=20 matche('cursorsalida',$identificador); fetch all in cursorsalida; "; $result =3D pg_query ($conn, $qry); $num =3D pg_num_rows($result); for ($i=3D0; $i < $num; $i++) { $r =3D pg_fetch_row($result, $i); (...) --------------- You have to pass a refcursor as input parameter. -----Message d'origine----- De : Andrew J. Kopciuch [mailto:akopciuch@olympusproject.org] Envoy=C3=A9 : Sunday, October 05, 2003 5:22 PM =C3=80 : Rod Taylor Cc : sebastien.baudry@baudry-engineering.com; Sebastien BAUDRY; pgsql-php@postgresql.org Objet : Re: [PHP] How to manipulate a cursor returned by a PL/pgSQL in a PHP On Sunday 05 October 2003 06:22, Rod Taylor wrote: > On Sun, 2003-10-05 at 04:38, Andrew J. Kopciuch wrote: > > On Sunday 05 October 2003 01:32, Sebastien BAUDRY wrote: > > > Hi. > > > My function returns a cursor and I don't know how to > > > fetch the cursor in my PHP script. > > > Anybody could help me? > > > > PHP does not directly support cursors under PostgreSQL. :-( > > Huh? Cursors in PostgreSQL are accessible via the standard query > interface within PHP. > > It's 2 queries, one to create the cursor, one to request the number of > tuples. PHP does not need any special logic to handle this. > > pg_query('DECLARE thecursor CURSOR FOR ....') > > pg_query('FETCH ...'); > > The fetch will act just like a select in regards to returned data. Yes. I should have elaborated a bit more.=20=20 I think this is in reference to his earlier post mentioning a REF CURSOR fr= om=20 a stored procedure. There is no support for binding a PHP var to a cursor= =20 like the Oracle functions offer. (OCINewCursor, OCIFreeCursor) You can always manage things directly with the query interface. I think he= =20 wants to manage things with the PHP interface. And you can't with the=20 PostgreSQL functions provided. AFAIK. That's all I was saying, cheers, Andy