Solved

accessing a  postgresql function (stored procedure) from php

Posted on 2001-06-04
2
337 Views
Last Modified: 2006-11-17
hai,
1.can anyone please tell me how to access a function  (stored procedure) in postgresql from php.
and
2.how should i bind a php variable?
my code goes below.
<html>
<body>
<?php
 $con = pg_connect("user= password=  dbname=");
 $result =pg_exec($con, "select * from test");
     
    now, $result will be the result set.
   i need to bind every column name of the table to a php variable so that i can use it in my program.

   for ex: if name is the first column name,then
    bind(NAME,$name);
       

   please help me.its very urgent.
0
Comment
Question by:prasanna_be_eee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
kalosi earned 150 total points
ID: 6152745
Hi,

1.
you should be able to call a pgsql function with pg_exec("select my_function_from_pgsql('$val')");

this should work

2.

you can write a function like this -

$numfilelds = pg_numfields($result);
//the number of columns affected by the query
$fileds = array();
for ($i=0; $i < $numfields; $i++) {
   $fields[] = pg_fieldname($fields, $i);
}
array with numeric key
this will fill the $fields array with the pgsql fieldnames.

or you can to it also this way:
  $f_name = pg_fieldname($fields, $i);
      $fields[$f_name] = $f_name;

you get an array the key representing the pgsql fieldname.

hope it helps
0
 

Author Comment

by:prasanna_be_eee
ID: 6154988
thanks kalosi,

      can u please tell me how to capture the return values(could be more than one) from the function(stored procedure).

   Regarding binding don't we have a built in function for binding php variables as we do in oracle

 (oracle: ocibindbyname(column_name,php_variable) )

    thanks in advance.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question