New News Entry

From: www(at)www(dot)postgresql(dot)com (World Wide Web Owner)
To: pgsql-www(at)postgresql(dot)org
Subject: New News Entry
Date: 2004-04-27 17:53:56
Message-ID: 20040427175356.33667CF542C@www.postgresql.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)commandprompt(dot)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 in the 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 examples of 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>

Responses

Browse pgsql-www by date

  From Date Subject
Next Message Bruno Wolff III 2004-04-27 18:23:16 Re: What can we learn from MySQL?
Previous Message Alexey Borzov 2004-04-27 17:52:01 Re: [HACKERS] What can we learn from MySQL?