Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 905879FA17A for ; Wed, 8 Nov 2006 17:52:21 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 29929-01 for ; Wed, 8 Nov 2006 17:52:17 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web35309.mail.mud.yahoo.com (web35309.mail.mud.yahoo.com [66.163.179.103]) by postgresql.org (Postfix) with SMTP id 6823A9F9EEF for ; Wed, 8 Nov 2006 17:52:17 -0400 (AST) Received: (qmail 35834 invoked by uid 60001); 8 Nov 2006 21:52:16 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:Cc:MIME-Version:Content-Type; b=jx6rBehTfbxfusO3j3NlWHSFjLXoAvb1JFAdKhYBlG/gHDS0VcdIPDFuKcnFlV4xgQmlkWeMsaOxdgFmYv8Fn0o68m2+iR7lzZpKCz6PgXZIe1P3TnlS9xi1cXn9BPUBi1ARWcCdqX/2ZjkZCys+bBfi+qOzD2PGZgsrVGrZAGI= ; Message-ID: <20061108215216.35832.qmail@web35309.mail.mud.yahoo.com> Received: from [74.98.189.48] by web35309.mail.mud.yahoo.com via HTTP; Wed, 08 Nov 2006 13:52:16 PST Date: Wed, 8 Nov 2006 13:52:16 -0800 (PST) From: Jean-Christophe Roux Subject: Re: function with array parameter To: andy.shellam-lists@mailnetwork.co.uk, Talha Khan Cc: pgsql-php@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-363435347-1163022736=:35585" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.373 tagged_above=0 required=5 tests=AWL, BAYES_00, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, DNS_FROM_RFC_WHOIS, HTML_30_40, HTML_MESSAGE X-Spam-Level: X-Archive-Number: 200611/25 X-Sequence-Number: 3642 --0-363435347-1163022736=:35585 Content-Type: text/plain; charset=ascii Content-Transfer-Encoding: quoted-printable Hello,=0A=0ALooks like it is best to forget about passing an array directly= between php and postgresql and instead rely on some string.=0A=0Athanks to= all=0A=0A=0A----- Original Message ----=0AFrom: Andy Shellam (Mailing List= s) =0ATo: Jean-Christophe Roux ; pgsql-php@postgresql.org=0ASent: Wednesday, November 8, 2006 4= :37:22 PM=0ASubject: Re: [PHP] function with array parameter=0A=0AYou could= do something like:=0A=0A(where $source_array is your array to pass to the = PGSQL function):=0A=0A=0A=0AThen send $query to the database. = That will create you something like =0A(if $source_array contains "param1"= and "param2"):=0A=0Aselect func_a_dummy("param1", "param2");=0A=0ARegards,= =0A=0AAndy.=0A=0AJean-Christophe Roux wrote:=0A> Hello,=0A>=0A> Thanks for = the answer but the resource connection is optional and in =0A> this script = there is no ambiguity since there is only one connection. =0A> I added the = connection to pg_query any way and the script still fails. =0A> I went thro= ugh archives and saw that others had the same problem with =0A> using a PHP= arrays as a parameter to a Postgresql function. I have not =0A> found a so= lution though; any thought?=0A>=0A> ----- Original Message ----=0A> From: T= alha Khan =0A> To: Jean-Christophe Roux =0A> Cc: pgsql-php@postgresql.org=0A> Sent: Wednesday, November 8, 200= 6 3:25:29 PM=0A> Subject: Re: [PHP] function with array parameter=0A>=0A> H= i Jean,=0A>=0A> >>$result =3D pg_query($query);=0A>=0A> try it as follows= =0A>=0A> $result=3Dpg_query($database,$query);=0A>=0A> where=0A>=0A> $datab= ase=3D=0A>=0A> Regards,=0A> Talha Khan=0A>=0A> On 11/9/06, *= Jean-Christophe Roux* > wrote= :=0A>=0A> Hello,=0A> I have a function that I would like to call fr= om a php script:=0A>=0A> CREATE OR REPLACE FUNCTION a_dummy(arr_in text= [])=0A> RETURNS text AS=0A> $BODY$=0A> declare=0A> begin= =0A> return arr_in[1];=0A> end;=0A> $BODY$=0A> LANGUA= GE 'plpgsql' VOLATILE;=0A>=0A> and the php code would be something like= that=0A> $arr;=0A> $arr[0] =3D "one";=0A> $arr[1] =3D 'two';= =0A> $query =3D "select func_a_dummy($arr)";=0A> $result =3D pg_que= ry($query);=0A> echo pg_fetch_result($result, 0, 0);=0A>=0A>=0A> bu= t the syntax is wrong. Any idea what I should do to make it work=0A> Th= ank you=0A>=0A>=0A>=0A>=0A> !DSPAM:37,45524c9640412067911618! =0A=0A=0A----= -----------------------(end of broadcast)---------------------------=0ATIP = 2: Don't 'kill -9' the postmaster=0A=0A=0A=0A=0A=0A=0A --0-363435347-1163022736=:35585 Content-Type: text/html; charset=ascii Content-Transfer-Encoding: quoted-printable
Hello,

Looks like it is best to forget about= passing an array directly between php and postgresql and instead rely on s= ome string.

thanks to all


----- Original Message = ----
From: Andy Shellam (Mailing Lists) <andy.shellam-lists@mailnetwo= rk.co.uk>
To: Jean-Christophe Roux <jcxxr@yahoo.com>; pgsql-php= @postgresql.org
Sent: Wednesday, November 8, 2006 4:37:22 PM
Subject:= Re: [PHP] function with array parameter

You could do something= like:

(where $source_array is your array to pass to the PGSQL funct= ion):

<?php
// start off the query string
$query =3D "selec= t func_a_dummy(";

// for each element of the array add to the string<= br>foreach ($source_array AS $func_parameter)
{
   &nb= sp;$query .=3D "\"" . $func_parameter . "\", ";
}

// we'll end up= with a trailing ", " on the end of the string due to the
final paramet= er, so remove it
$query =3D substring($query, 0, strlen($query) - 2);
// and close of the query string
$query .=3D ");";
?>

= Then send $query to the database.  That will create you something= like
(if $source_array contains "param1" and "param2"):

select = func_a_dummy("param1", "param2");

Regards,

Andy.

Jean-= Christophe Roux wrote:
> Hello,
>
> Thanks for the answer= but the resource connection is optional and in
> this script there = is no ambiguity since there is only one connection.
> I added the co= nnection to pg_query any way and the script still fails.
> I went th= rough archives and saw that others had the same problem with
> using a PHP arrays as a= parameter to a Postgresql function. I have not
> found a solution t= hough; any thought?
>
> ----- Original Message ----
> Fro= m: Talha Khan <talha.amjad@gmail.com>
> To: Jean-Christophe Rou= x <jcxxr@yahoo.com>
> Cc: pgsql-php@postgresql.org
> Sent= : Wednesday, November 8, 2006 3:25:29 PM
> Subject: Re: [PHP] functio= n with array parameter
>
> Hi Jean,
>
> >>$re= sult =3D pg_query($query);
>
> try it as follows
>
>= ; $result=3Dpg_query($database,$query);
>
> where
>
&g= t; $database=3D<database name>
>
> Regards,
> Talha= Khan
>
> On 11/9/06, *Jean-Christophe Roux* <jcxxr@yahoo.co= m
> <mailto:jcxxr@yahoo.com>> wrote:
>
> &= nbsp;   Hello,
>     I have a function = that I would like to call from a php script:
>
>     CREATE = OR REPLACE FUNCTION a_dummy(arr_in text[])
>    &= nbsp;  RETURNS text AS
>     $BODY$
>&= nbsp;    declare
>     begin
&g= t;         return arr_in[1];
>= ;     end;
>     $BODY$
&g= t;       LANGUAGE 'plpgsql' VOLATILE;
>=
>     and the php code would be something like t= hat
>     $arr;
>     $= arr[0] =3D "one";
>     $arr[1] =3D 'two';
>= ;     $query =3D "select func_a_dummy($arr)";
>&n= bsp;    $result =3D pg_query($query);
>  &nb= sp;  echo pg_fetch_result($result, 0, 0);
>
>
> = ;    but the syntax is wrong. Any idea what I should do to make it work
>=      Thank you
>
>
>
>
> = !DSPAM:37,45524c9640412067911618!


---------------------------(e= nd of broadcast)---------------------------
TIP 2: Don't 'kill -9' the p= ostmaster


--0-363435347-1163022736=:35585--