2025年9月25日: PostgreSQL 18 发布!

plPHP RC1 现已发布

发布于 2004-04-27

目前支持 SPI、复合类型、SetOf 函数、触发器、信任和非信任模式。

与上一个版本(Beta3)相比,新增了 SPI、复合类型、SetOf 函数和一次编译。下面是 plPHP RC1 版本目前的一些功能示例。

使用全局变量在函数调用之间存储数据:

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(); // 在我们的示例中将返回 "hello plphp"

数据库访问 (SPI)

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

$rv = spi_exec_query($query);

结果将按如下方式访问:

$res = $rv[''status'']; // 在我们的示例中为 SPI_OK_INSERT

$nrows = $rv[''rows''];

SetOf 函数

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);

将返回

f1 | f2 | f3

----+-------+----------

1 | hello | world

2 | hello | postgres

3 | hello | plphp

plPHP 可以在 Command Prompt, Inc. 的社区页面上找到,链接在此:此处

本文已从先前版本的 PostgreSQL 网站迁移。对于迁移过程中可能出现的任何格式问题,我们深表歉意。