Creating PostgreSQL stored function and calling the same using PHP script.
The query tool, pgAdmin3.exe of PostgreSQL is a fantastic query tool. Unlike PL-SQL, the function created with SQL-Query tool, will help to create a SQL query.

The SQL Developer  tool for oracle creates PL/SQL Block with codes to call the custom functions.

 

How to Query stored function with PHP :

//PostgreSQL SQL query script:

$sql="SELECT round (cfcal($celcius),2)";
$result = pg_query($dbconn,$sql);
 

//Oracle stored function for the similar code

$stid = oci_parse($conn, "begin :bv:=CTOF(29.25); end;");
echo "uses oci_bind_name </br/>";
oci_bind_by_name($stid, ":bv", $p1, 6);

 

Workstation: manas9 : windows 8

pwd: postgre_manas9

Now open a query pane

Opens a sql query window

Now add any value you want

 
Use this script with PHP


<?php
class StringClass
{
public $var1;public $num =0;

public function __construct($param1)
{
$this->var1 = $param1;
//echo "object constructed ";
}
public function __destruct()
{

// echo "<br/>object destructed";
}

public function __toString()
{
return $this->var1;
}

}
?>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PostreSQL:psql_funct_param2.php</title>
<meta name="description" >
</head>
<body>

<?php
$str1= "<br/>Callling Stored function with php <br/>" ;
$class1= new StringClass($str1);
echo $class1;

//$class = new StringClass('Hello');
//echo $class;
//
$host = "localhost";
$user = "manas237";
$pass = "pwmanas237";
$db = "pgsdemo1";
$celcius = 29.25;
// open a connection to the database server
$dbconn = pg_connect ("host=$host dbname=$db user=$user password=$pass");
if(!$dbconn){
echo "Error : Unable to open database\n";
} else {
echo "Opened database successfully<br/>";
}
$sql="SELECT round (cfcal($celcius),2)";
$result = pg_query($dbconn,$sql);
if(!$result){
echo pg_last_error($db);
exit;
}
$class2 = new StringClass($sql);
echo "<br/> query string ". $class2;
echo "<br/>Temp : ".$celcius. "<sup>0</sup>C =". pg_fetch_result($result,0)."<sup>0</sup> F";
?>
</body>
</html>