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
Solved

accessing a  postgresql function (stored procedure) from php

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

837 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