Solved

accessing a  postgresql function (stored procedure) from php

Posted on 2001-06-04
2
331 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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 count occurrences of each item in an array.

743 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

15 Experts available now in Live!

Get 1:1 Help Now