New News Entry - Mailing list pgsql-www

From www@www.postgresql.com (World Wide Web Owner)
Subject New News Entry
Date
Msg-id 20040427175356.33667CF542C@www.postgresql.com
Whole thread Raw
Responses Re: New News Entry
Re: New News Entry
List pgsql-www
A new entry has been added to the news database.

Database Admin: http://www.postgresql.org/admin/edit_news.php?182

Submitted by: jd@commandprompt.com
Headline: plPHP RC1 is now available
Summary:

PL/PHP is a loadable procedural language that enables you to write PostgreSQL functions (store procedures) and triggers
inthe PHP programming language. It works with 7.3.x and 7.4.x. 

Story:

It currently supports SPI, composite types, SetOf function, triggers, trusted, and untrusted modes.

From the last release (Beta3) SPI, composite types, SetOf functions, and compile once have been added. Below are some
examplesof what the RC1 version of plPHP is currently capable of. 

Using global variables to store data between function callsL

<pre>
CREATE OR REPLACE FUNCTION set_var(text) RETURNS text AS \'
global $_SHARED;
$_SHARED[\'\'first\'\']=$args[0];
return \'\'ok\'\';
\' LANGUAGE plphp

CREATE OR REPLACE FUNCTION get_var() RETURNS text AS \'
global $_SHARED;
return $_SHARED[\'\'first\'\'];
\' LANGUAGE plphp;

SELECT set_var(\'hello plphp\');
SELECT get_var(); //will return \"hello plphp\" in our example

</pre>
Database Access (SPI):

$query = \"INSERT INTO my_table VALUES (1, \'\'test\'\')\";
$rv = spi_exec_query($query);

The result would be accessed as:

$res = $rv[\'\'status\'\']; //SPI_OK_INSERT in our example
$nrows = $rv[\'\'rows\'\'];
</pre>

SetOf functions:

<pre>
CREATE TYPE __testsetphp AS (f1 integer, f2 text, f3 text);

CREATE OR REPLACE FUNCTION php_set(integer) RETURNS SETOF __testsetphp AS \'
$ret[0][0]=$args[0];
$ret[0][1]=\"hello\";
$ret[0][2]=\"world\";
$ret[1][0]=2*$args[0];
$ret[1][1]=\"hello\";
$ret[1][2]=\"postgres\";
$ret[2][0]=3*$args[0];
$ret[2][1]=\"hello\";
$ret[2][2]=\"plphp\";
return $ret;
\' LANGUAGE \'plphp\';

SELECT * FROM php_set(1);

Will return:
 f1 |  f2   |    f3
----+-------+----------
  1 | hello | world
  2 | hello | postgres
  3 | hello | plphp

</pre>

plPHP can be found at the Command Prompt, Inc. community pages located <a
href=\"https://www.commandprompt.com/entry.lxp?lxpe=294\">here</a> 



pgsql-www by date:

Previous
From: "Marc G. Fournier"
Date:
Subject: More prominent links ...
Next
From: Peter Eisentraut
Date:
Subject: Re: New News Entry