pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
PLPGSQL - PHP data querying
3+ messages / 3 participants
[nested] [flat]

* PLPGSQL - PHP data querying
@ 2006-12-06 10:20  Ganesh Laxmanmurthy <lganimys@yahoo.co.in>
  0 siblings, 2 replies; 3+ messages in thread

From: Ganesh Laxmanmurthy @ 2006-12-06 10:20 UTC (permalink / raw)
  To: pgsql-php

Dear All:

Regarding PHP & PLPGSQL Programming. I am new to
PLPGSQL.

I wish someone suggest me the solution for the below
requirement even though it is very simple as I am new
to the subject and could not find an answer which I
can understand.

I have a table by name 'users' with several columns.

I want to query "select * from users' from PHP to
Postgresql through PLPGSQL.

Therefore I need

1. The practical syntax for the PLPGSQL function

2. The practical syntax for calling and displaying of
the returned recordset from PHP.

With the above I would be able to develop futher
programs.

I would be thankful for the same.

Thanks in advance

Regards

Ganesh


		
__________________________________________________________
Yahoo! India Answers: Share what you know. Learn something new
http://in.answers.yahoo.com/



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: PLPGSQL - PHP data querying
@ 2006-12-06 11:02  Adam Witney <awitney@sgul.ac.uk>
  parent: Ganesh Laxmanmurthy <lganimys@yahoo.co.in>
  1 sibling, 0 replies; 3+ messages in thread

From: Adam Witney @ 2006-12-06 11:02 UTC (permalink / raw)
  To: Ganesh Laxmanmurthy <lganimys@yahoo.co.in>; +Cc: pgsql-php



Ganesh Laxmanmurthy wrote:
> Dear All:
> 
> Regarding PHP & PLPGSQL Programming. I am new to
> PLPGSQL.
> 
> I wish someone suggest me the solution for the below
> requirement even though it is very simple as I am new
> to the subject and could not find an answer which I
> can understand.
> 
> I have a table by name 'users' with several columns.
> 
> I want to query "select * from users' from PHP to
> Postgresql through PLPGSQL.
> 
> Therefore I need
> 
> 1. The practical syntax for the PLPGSQL function
> 
> 2. The practical syntax for calling and displaying of
> the returned recordset from PHP.
> 
> With the above I would be able to develop futher
> programs.
> 
> I would be thankful for the same.

here is some untested code, but will give one way of doing it (note
there is also no great error checking in it):


CREATE TABLE users (id int, name text);

CREATE OR REPLACE FUNCTION my_function() RETURNS SETOF record AS '
 DECLARE
    _record record;

 BEGIN

      FOR _record IN SELECT * FROM users
       LOOP
         RETURN NEXT _record;
       END LOOP;

       RETURN;
 END;

' LANGUAGE 'plpgsql';


############################# PHP code #############################

$connstr = "dbname=".$dbname." host=".$host." port=".$port."
user=".$user." password=".$passwd;

$dbh = pg_connect($connstr);


$sql = "SELECT * FROM my_function() AS (id int, name text);";

if($stat = pg_exec($dbh, $sql);)
   {
    if($rows = pg_numrows($stat))
       {
        for($i=0; $i < $rows; $i++)
            {
             $data = pg_fetch_array($stat, $i);

             echo $data['id']." -- ".$data['name']."<br>";
            }
       }
   }

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: PLPGSQL - PHP data querying
@ 2006-12-06 13:17  Andy Shellam (Mailing Lists) <andy.shellam-lists@mailnetwork.co.uk>
  parent: Ganesh Laxmanmurthy <lganimys@yahoo.co.in>
  1 sibling, 0 replies; 3+ messages in thread

From: Andy Shellam (Mailing Lists) @ 2006-12-06 13:17 UTC (permalink / raw)
  To: Ganesh Laxmanmurthy <lganimys@yahoo.co.in>; +Cc: pgsql-php

Why do you specifically want to do this through PlPgsql?

You can just as easily do a query directly from PHP to get a recordset, 
and it gives less server overhead.

Andy.

Ganesh Laxmanmurthy wrote:
> Dear All:
>
> Regarding PHP & PLPGSQL Programming. I am new to
> PLPGSQL.
>
> I wish someone suggest me the solution for the below
> requirement even though it is very simple as I am new
> to the subject and could not find an answer which I
> can understand.
>
> I have a table by name 'users' with several columns.
>
> I want to query "select * from users' from PHP to
> Postgresql through PLPGSQL.
>
> Therefore I need
>
> 1. The practical syntax for the PLPGSQL function
>
> 2. The practical syntax for calling and displaying of
> the returned recordset from PHP.
>
> With the above I would be able to develop futher
> programs.
>
> I would be thankful for the same.
>
> Thanks in advance
>
> Regards
>
> Ganesh
>
>
> 		
> __________________________________________________________
> Yahoo! India Answers: Share what you know. Learn something new
> http://in.answers.yahoo.com/
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>
> !DSPAM:37,45769b3640411164512130!
>
>
>   


-- 
Andy Shellam
NetServe Support Team

the Mail Network
"an alternative in a standardised world"

p: +44 (0) 121 288 0832/0839
m: +44 (0) 7818 000834




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2006-12-06 13:17 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-12-06 10:20 PLPGSQL - PHP data querying Ganesh Laxmanmurthy <lganimys@yahoo.co.in>
2006-12-06 11:02 ` Adam Witney <awitney@sgul.ac.uk>
2006-12-06 13:17 ` Andy Shellam (Mailing Lists) <andy.shellam-lists@mailnetwork.co.uk>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox