From jcxxr@yahoo.com Wed Nov 8 20:07:38 2006 Received: from localhost (uranus.hub.org [200.46.204.60]) by postgresql.org (Postfix) with ESMTP id 389389FB26B for ; Wed, 8 Nov 2006 16:07:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.60]) (amavisd-new, port 10024) with ESMTP id 83574-05 for ; Wed, 8 Nov 2006 16:07:35 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web35311.mail.mud.yahoo.com (web35311.mail.mud.yahoo.com [66.163.179.105]) by postgresql.org (Postfix) with SMTP id 4AE749F9858 for ; Wed, 8 Nov 2006 16:07:27 -0400 (AST) Received: (qmail 43285 invoked by uid 60001); 8 Nov 2006 20:07:24 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type; b=Zh9LPRx2QR9IBj7guScV7QT0mP/dvjvd16FZFZitcaJD6xEVBAAHqlNVFmmc3NqhkRZtJw3vJpWyYBYk510HILJKWe3BxB67QK8/xnmzIGu0NwTNUTcPm4vIZlCc6NMroSz8zvRaen8Rbs3oZY40+AbzCj81nyAp7jlXU1CFmWs= ; Message-ID: <20061108200724.43283.qmail@web35311.mail.mud.yahoo.com> Received: from [74.98.189.48] by web35311.mail.mud.yahoo.com via HTTP; Wed, 08 Nov 2006 12:07:24 PST Date: Wed, 8 Nov 2006 12:07:23 -0800 (PST) From: Jean-Christophe Roux Subject: function with array parameter To: pgsql-php@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-2016155230-1163016443=:43259" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.131 tagged_above=0 required=5 tests=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/19 X-Sequence-Number: 3636 --0-2016155230-1163016443=:43259 Content-Type: text/plain; charset=ascii Content-Transfer-Encoding: quoted-printable Hello,=0AI have a function that I would like to call from a php script:=0A= =0ACREATE OR REPLACE FUNCTION a_dummy(arr_in text[])=0A RETURNS text AS=0A= $BODY$=0Adeclare=0Abegin=0A return arr_in[1];=0Aend;=0A$BODY$=0A LANGUA= GE 'plpgsql' VOLATILE;=0A=0Aand the php code would be something like that= =0A$arr;=0A$arr[0] =3D "one";=0A$arr[1] =3D 'two';=0A$query =3D "select fun= c_a_dummy($arr)";=0A$result =3D pg_query($query);=0Aecho pg_fetch_result($r= esult, 0, 0);=0A=0A=0Abut the syntax is wrong. Any idea what I should do to= make it work=0AThank you=0A=0A=0A=0A --0-2016155230-1163016443=:43259 Content-Type: text/html; charset=ascii Content-Transfer-Encoding: quoted-printable
Hello,
I have a function that I would like to call = from a php script:

CREATE OR REPLACE FUNCTION a_dummy(arr_in text[])=
  RETURNS text AS
$BODY$
declare
begin
  &nb= sp; return arr_in[1];
end;
$BODY$
  LANGUAGE 'plpgsql' VOLATI= LE;

and the php code would be something like that
$arr;
$arr[0= ] =3D "one";
$arr[1] =3D 'two';
$query =3D "select func_a_dummy($arr)= ";
$result =3D pg_query($query);
echo pg_fetch_result($result, 0, 0);=


but the syntax is wrong. Any idea what I should do to make it w= ork
Thank you

--0-2016155230-1163016443=:43259-- From talha.amjad@gmail.com Wed Nov 8 20:25:34 2006 Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 9204E9FA1FD for ; Wed, 8 Nov 2006 16:25:34 -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 07079-05 for ; Wed, 8 Nov 2006 16:25:31 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.168]) by postgresql.org (Postfix) with ESMTP id 639E19FA17A for ; Wed, 8 Nov 2006 16:25:31 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id k3so11485ugf for ; Wed, 08 Nov 2006 12:25:29 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=oZ6WeYauJmdc9St7m0clPZ2uag6ObeNEkNf6tS61wKfdp+avvzyRuP6Ic6bPyVRPGOQOYrH5hxsslhTYaeu9uYXy93LznzPHolre3vu/FzWa3X9kOlkss3U3sD4u9oNZ/QVwD03Cvl0Lcfvw56yYfBa2cUs3c/pNTBcLfRQDuSs= Received: by 10.82.129.8 with SMTP id b8mr6440bud.1163017529535; Wed, 08 Nov 2006 12:25:29 -0800 (PST) Received: by 10.82.158.7 with HTTP; Wed, 8 Nov 2006 12:25:29 -0800 (PST) Message-ID: Date: Thu, 9 Nov 2006 01:25:29 +0500 From: "Talha Khan" To: "Jean-Christophe Roux" Subject: Re: function with array parameter Cc: pgsql-php@postgresql.org In-Reply-To: <20061108200724.43283.qmail@web35311.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_27610_9570405.1163017529444" References: <20061108200724.43283.qmail@web35311.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/20 X-Sequence-Number: 3637 ------=_Part_27610_9570405.1163017529444 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi Jean, >>$result = pg_query($query); try it as follows $result=pg_query($database,$query); where $database= Regards, Talha Khan On 11/9/06, Jean-Christophe Roux wrote: > > Hello, > I have a function that I would like to call from a php script: > > CREATE OR REPLACE FUNCTION a_dummy(arr_in text[]) > RETURNS text AS > $BODY$ > declare > begin > return arr_in[1]; > end; > $BODY$ > LANGUAGE 'plpgsql' VOLATILE; > > and the php code would be something like that > $arr; > $arr[0] = "one"; > $arr[1] = 'two'; > $query = "select func_a_dummy($arr)"; > $result = pg_query($query); > echo pg_fetch_result($result, 0, 0); > > > but the syntax is wrong. Any idea what I should do to make it work > Thank you > > ------=_Part_27610_9570405.1163017529444 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi Jean,

>>$result = pg_query($query);

try it as follows

$result=pg_query($database,$query);

where

$database=<database name>

Regards,
Talha Khan

On 11/9/06, Jean-Christophe Roux <jcxxr@yahoo.com> wrote:
Hello,
I have a function that I would like to call from a php script:

CREATE OR REPLACE FUNCTION a_dummy(arr_in text[])
  RETURNS text AS
$BODY$
declare
begin
    return arr_in[1];
end;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;

and the php code would be something like that
$arr;
$arr[0] = "one";
$arr[1] = 'two';
$query = "select func_a_dummy($arr)";
$result = pg_query($query);
echo pg_fetch_result($result, 0, 0);


but the syntax is wrong. Any idea what I should do to make it work
Thank you


------=_Part_27610_9570405.1163017529444-- From ahodgson@simkin.ca Wed Nov 8 20:30:04 2006 Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id CBB079FA1FD for ; Wed, 8 Nov 2006 16:30:04 -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 08549-06 for ; Wed, 8 Nov 2006 16:30:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from skynet.simkin.ca (skynet.simkin.ca [199.175.137.210]) by postgresql.org (Postfix) with ESMTP id CA8CD9FA17A for ; Wed, 8 Nov 2006 16:30:00 -0400 (AST) Received: from hal.simkin.ca (S0106000c6eb33e73.vc.shawcable.net [24.80.109.220]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by skynet.simkin.ca (Postfix) with ESMTP id 021C2FAC5 for ; Wed, 8 Nov 2006 12:29:58 -0800 (PST) From: Alan Hodgson Organization: Simkin Network Consulting To: pgsql-php@postgresql.org Subject: Re: function with array parameter Date: Wed, 8 Nov 2006 12:29:57 -0800 User-Agent: KMail/1.9.1 References: <20061108200724.43283.qmail@web35311.mail.mud.yahoo.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200611081229.57318@hal.medialogik.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/21 X-Sequence-Number: 3638 > On 11/9/06, Jean-Christophe Roux wrote: > > Hello, > > I have a function that I would like to call from a php script: > > > > CREATE OR REPLACE FUNCTION a_dummy(arr_in text[]) > > RETURNS text AS > > $BODY$ > > declare > > begin > > return arr_in[1]; > > end; > > $BODY$ > > LANGUAGE 'plpgsql' VOLATILE; > > > > and the php code would be something like that > > $arr; > > $arr[0] = "one"; > > $arr[1] = 'two'; > > $query = "select func_a_dummy($arr)"; > > $result = pg_query($query); > > echo pg_fetch_result($result, 0, 0); A PHP array doesn't translate to a PostgreSQL array. You have to build up a string to pass to the function ( ie. '{"value1","value2"}' ) . -- "Emacs is great. But hang onto vim, because you'll still need a decent text editor." - seen on /. From jcxxr@yahoo.com Wed Nov 8 21:30:39 2006 Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 5B9D99FB277 for ; Wed, 8 Nov 2006 17:30:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 81983-07 for ; Wed, 8 Nov 2006 21:30:23 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web35301.mail.mud.yahoo.com (web35301.mail.mud.yahoo.com [66.163.179.95]) by postgresql.org (Postfix) with SMTP id AF1D09FA17A for ; Wed, 8 Nov 2006 17:30:23 -0400 (AST) Received: (qmail 62183 invoked by uid 60001); 8 Nov 2006 21:30:22 -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=iUAXj3RTUbCKozUmEoEX8FrveoTIlWhViyz6U6L92iJCFuXtFKFxrB4RxYBY7zcbxhiVkwoe8WNKZgQOgXBnT1SD5+ZZMBb2WJMQgIAvDWJ66AcptCMf69+/vJWrfjLI7qaeWvHcl43Por85TtzMAfqme5UzHc349ZIPI0qpK3Q= ; Message-ID: <20061108213022.62179.qmail@web35301.mail.mud.yahoo.com> Received: from [74.98.189.48] by web35301.mail.mud.yahoo.com via HTTP; Wed, 08 Nov 2006 13:30:22 PST Date: Wed, 8 Nov 2006 13:30:22 -0800 (PST) From: Jean-Christophe Roux Subject: Re: function with array parameter To: Talha Khan Cc: pgsql-php@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1675484758-1163021422=:62120" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/22 X-Sequence-Number: 3639 --0-1675484758-1163021422=:62120 Content-Type: text/plain; charset=ascii Content-Transfer-Encoding: quoted-printable Hello,=0A=0AThanks for the answer but the resource connection is optional a= nd in this script there is no ambiguity since there is only one connection.= I added the connection to pg_query any way and the script still fails. I w= ent through 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 solu= tion though; any thought?=0A=0A----- Original Message ----=0AFrom: Talha Kh= an =0ATo: Jean-Christophe Roux =0AC= c: pgsql-php@postgresql.org=0ASent: Wednesday, November 8, 2006 3:25:29 PM= =0ASubject: Re: [PHP] function with array parameter=0A=0AHi Jean,=0A=0A>>$r= esult =3D pg_query($query);=0A=0Atry it as follows=0A=0A$result=3Dpg_query(= $database,$query);=0A=0Awhere=0A=0A$database=3D=0A=0ARegards= ,=0A=0ATalha Khan=0A=0AOn 11/9/06, Jean-Christophe Roux w= rote:=0AHello,=0AI have a function that I would like to call from a php scr= ipt:=0A=0ACREATE OR REPLACE FUNCTION a_dummy(arr_in text[])=0A=0A RETURNS = text AS=0A$BODY$=0Adeclare=0Abegin=0A return arr_in[1];=0Aend;=0A$BODY$= =0A LANGUAGE 'plpgsql' VOLATILE;=0A=0Aand the php code would be something = like that=0A$arr;=0A$arr[0] =3D "one";=0A$arr[1] =3D 'two';=0A=0A$query =3D= "select func_a_dummy($arr)";=0A$result =3D pg_query($query);=0Aecho pg_fet= ch_result($result, 0, 0);=0A=0A=0Abut the syntax is wrong. Any idea what I = should do to make it work=0AThank you=0A=0A=0A=0A=0A=0A=0A=0A=0A=0A=0A=0A= =0A=0A=0A --0-1675484758-1163021422=:62120 Content-Type: text/html; charset=ascii Content-Transfer-Encoding: quoted-printable
Hello,

Thanks for the answer but the resourc= e connection is optional and in this script there is no ambiguity since the= re is only one connection. I added the connection to pg_query any way and t= he script still fails. I went through archives and saw that others had the = same problem with using a PHP arrays as a parameter to a Postgresql functio= n. I have not found a solution though; any thought?

----- Or= iginal Message ----
From: Talha Khan <talha.amjad@gmail.com>
To= : Jean-Christophe Roux <jcxxr@yahoo.com>
Cc: pgsql-php@postgresql.= org
Sent: Wednesday, November 8, 2006 3:25:29 PM
Subject: Re: [PHP] f= unction with array parameter

Hi Jean,

>>$result =3D pg_query($query);
=
try it as follows

$result=3Dpg_query($database,$query);

w= here

$database=3D<database name>

Regards,
=0ATalha Khan

On 11/9/06, Jean-Christophe Roux <jcxxr@yahoo.com> wrote:
=0A
Hello,
I have a function that I would like to call from a php script:=

CREATE OR REPLACE FUNCTION a_dummy(arr_in text[])
=0A  RETU= RNS text AS
$BODY$
declare
begin
    return arr_= in[1];
end;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;

and = the php code would be something like that
$arr;
$arr[0] =3D "one";$arr[1] =3D 'two';=0A
$query =3D "select func_a_dummy($arr)";
$resul= t =3D pg_query($query);
echo pg_fetch_result($result, 0, 0);


= but the syntax is wrong. Any idea what I should do to make it work
Thank= you
=0A

=0A

=0A


--0-1675484758-1163021422=:62120-- From andy.shellam-lists@mailnetwork.co.uk Wed Nov 8 21:37:26 2006 Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id EA4669F9EEF for ; Wed, 8 Nov 2006 17:37:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 82803-09 for ; Wed, 8 Nov 2006 21:37:23 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from perth.mailnetwork.co.uk (perth.mailnetwork.co.uk [80.175.28.46]) by postgresql.org (Postfix) with ESMTP id 9893E9F9DAD for ; Wed, 8 Nov 2006 17:37:23 -0400 (AST) Received: from 80-47-93-17.lond-hex.dynamic.dial.as9105.com ([80.47.93.17]:1604 helo=[192.168.1.2]) by perth.mailnetwork.co.uk with esmtpa (Exim 4.63) (envelope-from ) id 1Ghv6p-0007cV-HN; Wed, 08 Nov 2006 21:37:23 +0000 Message-ID: <45524E12.30307@mailnetwork.co.uk> Date: Wed, 08 Nov 2006 21:37:22 +0000 From: "Andy Shellam (Mailing Lists)" Reply-To: andy.shellam-lists@mailnetwork.co.uk Organization: the Mail Network User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 To: Jean-Christophe Roux , pgsql-php@postgresql.org Subject: Re: function with array parameter References: <20061108213022.62179.qmail@web35301.mail.mud.yahoo.com> In-Reply-To: <20061108213022.62179.qmail@web35301.mail.mud.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/24 X-Sequence-Number: 3641 You could do something like: (where $source_array is your array to pass to the PGSQL function): 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 connection to pg_query any way and the script still fails. > I went through 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 though; any thought? > > ----- Original Message ---- > From: Talha Khan > To: Jean-Christophe Roux > Cc: pgsql-php@postgresql.org > Sent: Wednesday, November 8, 2006 3:25:29 PM > Subject: Re: [PHP] function with array parameter > > Hi Jean, > > >>$result = pg_query($query); > > try it as follows > > $result=pg_query($database,$query); > > where > > $database= > > Regards, > Talha Khan > > On 11/9/06, *Jean-Christophe Roux* > wrote: > > Hello, > I have a function that I would like to call from a php script: > > CREATE OR REPLACE FUNCTION a_dummy(arr_in text[]) > RETURNS text AS > $BODY$ > declare > begin > return arr_in[1]; > end; > $BODY$ > LANGUAGE 'plpgsql' VOLATILE; > > and the php code would be something like that > $arr; > $arr[0] = "one"; > $arr[1] = 'two'; > $query = "select func_a_dummy($arr)"; > $result = pg_query($query); > 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! From jcxxr@yahoo.com Wed Nov 8 21:52:21 2006 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-- From andy.shellam-lists@mailnetwork.co.uk Wed Nov 8 21:54:43 2006 Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 7738D9FB235 for ; Wed, 8 Nov 2006 17:54:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 87490-01 for ; Wed, 8 Nov 2006 21:54:40 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from perth.mailnetwork.co.uk (perth.mailnetwork.co.uk [80.175.28.46]) by postgresql.org (Postfix) with ESMTP id 1FE5F9FA17A for ; Wed, 8 Nov 2006 17:54:39 -0400 (AST) Received: from 80-47-93-17.lond-hex.dynamic.dial.as9105.com ([80.47.93.17]:1742 helo=[192.168.1.2]) by perth.mailnetwork.co.uk with esmtpa (Exim 4.63) (envelope-from ) id 1GhvNZ-00082C-Fh; Wed, 08 Nov 2006 21:54:42 +0000 Message-ID: <45525220.7030506@mailnetwork.co.uk> Date: Wed, 08 Nov 2006 21:54:40 +0000 From: "Andy Shellam (Mailing Lists)" Reply-To: andy.shellam-lists@mailnetwork.co.uk Organization: the Mail Network User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 To: Jean-Christophe Roux CC: pgsql-php@postgresql.org Subject: Re: function with array parameter References: <20061108215216.35832.qmail@web35309.mail.mud.yahoo.com> In-Reply-To: <20061108215216.35832.qmail@web35309.mail.mud.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/26 X-Sequence-Number: 3643 Yes - PHP arrays will inevitably be different to PostgreSQL arrays. Jean-Christophe Roux wrote: > Hello, > > Looks like it is best to forget about passing an array directly > between php and postgresql and instead rely on some string. > > thanks to all > > > ----- Original Message ---- > From: Andy Shellam (Mailing Lists) > To: Jean-Christophe Roux ; 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 function): > > // start off the query string > $query = "select func_a_dummy("; > > // for each element of the array add to the string > foreach ($source_array AS $func_parameter) > { > $query .= "\"" . $func_parameter . "\", "; > } > > // we'll end up with a trailing ", " on the end of the string due to the > final parameter, so remove it > $query = substring($query, 0, strlen($query) - 2); > > // and close of the query string > $query .= ");"; > ?> > > 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 connection to pg_query any way and the script still fails. > > I went through 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 though; any thought? > > > > ----- Original Message ---- > > From: Talha Khan > > To: Jean-Christophe Roux > > Cc: pgsql-php@postgresql.org > > Sent: Wednesday, November 8, 2006 3:25:29 PM > > Subject: Re: [PHP] function with array parameter > > > > Hi Jean, > > > > >>$result = pg_query($query); > > > > try it as follows > > > > $result=pg_query($database,$query); > > > > where > > > > $database= > > > > Regards, > > Talha Khan > > > > On 11/9/06, *Jean-Christophe Roux* > > wrote: > > > > Hello, > > I have a function that I would like to call from a php script: > > > > CREATE OR REPLACE FUNCTION a_dummy(arr_in text[]) > > RETURNS text AS > > $BODY$ > > declare > > begin > > return arr_in[1]; > > end; > > $BODY$ > > LANGUAGE 'plpgsql' VOLATILE; > > > > and the php code would be something like that > > $arr; > > $arr[0] = "one"; > > $arr[1] = 'two'; > > $query = "select func_a_dummy($arr)"; > > $result = pg_query($query); > > echo pg_fetch_result($result, 0, 0); > > > > > > but the syntax is wrong. Any idea what I should do to make it work > > Thank you > > > > > > > > > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster > > > !DSPAM:37,455251b340411983042122!