Solved

accessing a  postgresql function (stored procedure) from php

Posted on 2001-06-04
2
339 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

626 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