function with array parameter
function with array parameter
am 08.11.2006 21:07:23 von Jean-Christophe Roux
--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;
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 fun=
c_a_dummy($arr)";=0A$result =3D pg_query($query);=0Aecho pg_fetch_result($r=
esult, 0, 0);
=0Abut the syntax is wrong. Any idea what I should do to=
make it work=0AThank you
--0-2016155230-1163016443=:43259
Content-Type: text/html; charset=ascii
Content-Transfer-Encoding: quoted-printable
ad>
font-size:12pt">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--
Re: function with array parameter
am 08.11.2006 21:25:29 von Talha Khan
------=_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 <> 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--
Re: function with array parameter
am 08.11.2006 21:29:57 von Alan Hodgson
> 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 /.
---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend
Re: function with array parameter
am 08.11.2006 22:30:22 von Jean-Christophe Roux
--0-1675484758-1163021422=:62120
Content-Type: text/plain; charset=ascii
Content-Transfer-Encoding: quoted-printable
Hello,
Thanks 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?
----- 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
Hi Jean,
>>$r=
esult =3D pg_query($query);
try it as follows
$result=3Dpg_query(=
$database,$query);
where
$database=3D
Regards=
,
Talha Khan
On 11/9/06, Jean-Christophe Roux w=
rote:=0AHello,=0AI have a function that I would like to call from a php scr=
ipt:
CREATE OR REPLACE FUNCTION a_dummy(arr_in text[])
RETURNS =
text AS=0A$BODY$=0Adeclare=0Abegin=0A return arr_in[1];=0Aend;=0A$BODY$=
=0A LANGUAGE 'plpgsql' VOLATILE;
and the php code would be something =
like that=0A$arr;=0A$arr[0] =3D "one";=0A$arr[1] =3D 'two';
$query =3D=
"select func_a_dummy($arr)";=0A$result =3D pg_query($query);=0Aecho pg_fet=
ch_result($result, 0, 0);
=0Abut the syntax is wrong. Any idea what I =
should do to make it work=0AThank you
=
=0A
--0-1675484758-1163021422=:62120
Content-Type: text/html; charset=ascii
Content-Transfer-Encoding: quoted-printable
ad>
font-size:12pt">
erif; font-size: 12pt;">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?
nt-family: times new roman,new york,times,serif; font-size: 12pt;">----- 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>
ail_quote">Regards,
=0ATalha Khan
On 11/9/06,
endername">Jean-Christophe Roux <
k" href=3D"mailto:jcxxr@yahoo.com">jcxxr@yahoo.com> wrote:
ockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, 204=
, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">=0A
=3D"font-family: times new roman,new york,times,serif; font-size: 12pt;">
iv>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
iv>
--0-1675484758-1163021422=:62120--
Re: function with array parameter
am 08.11.2006 22:37:22 von andy.shellam-lists
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
>
>
>
>
> !DSPAM:37,45524c9640412067911618!
---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster
Re: function with array parameter
am 08.11.2006 22:52:16 von Jean-Christophe Roux
--0-363435347-1163022736=:35585
Content-Type: text/plain; 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 some string.
thanks to=
all
=0A----- Original Message ----=0AFrom: Andy Shellam (Mailing List=
s) =0ATo: Jean-Christophe Roux
@yahoo.com>; pgsql-php@postgresql.org=0ASent: Wednesday, November 8, 2006 4=
:37:22 PM=0ASubject: Re: [PHP] function with array parameter
You could=
do something like:
(where $source_array is your array to pass to the =
PGSQL function):
elect func_a_dummy(";
// for each element of the array add to the stri=
ng=0Aforeach ($source_array AS $func_parameter)=0A{=0A $query .=3D "\"" =
.. $func_parameter . "\", ";=0A}
// we'll end up with a trailing ", " o=
n the end of the string due to the =0Afinal parameter, so remove it=0A$quer=
y =3D substring($query, 0, strlen($query) - 2);
// and close of the qu=
ery string=0A$query .=3D ");";=0A?>
Then send $query to the database. =
That will create you something like =0A(if $source_array contains "param1"=
and "param2"):
select func_a_dummy("param1", "param2");
Regards,=
Andy.
Jean-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
..com>=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----=
-----------------------(end of broadcast)---------------------------=0ATIP =
2: Don't 'kill -9' the postmaster
=0A
--0-363435347-1163022736=:35585
Content-Type: text/html; charset=ascii
Content-Transfer-Encoding: quoted-printable
ad>
font-size:12pt">
erif; font-size: 12pt;">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
s new roman,new york,times,serif; font-size: 12pt;">----- 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--
Re: function with array parameter
am 08.11.2006 22:54:40 von andy.shellam-lists
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!
---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster