Solved

accessing a  postgresql function (stored procedure) from php

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now