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!