Project

General

Profile

CreateLang » History » Version 8

Álvaro Herrera, 03/19/2009 08:43 AM
highlight version numbers

1 1 Álvaro Herrera
2 8 Álvaro Herrera
h1. Creating the PL/php language in a [[PostgreSQL]] database
3
4
5 1 Álvaro Herrera
The first thing you need is to have a PL/php entry in the pg_pltemplate system catalog.
6 6 Álvaro Herrera
7 8 Álvaro Herrera
In *8.1 and 8.2* you can insert one by issuing, as a superuser:
8
<pre>
9 5 Álvaro Herrera
INSERT INTO pg_pltemplate VALUES
10 1 Álvaro Herrera
('plphp', 't', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp', NULL);
11
12 5 Álvaro Herrera
INSERT INTO pg_pltemplate VALUES
13 1 Álvaro Herrera
('plphpu', 'f', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp', NULL);
14 8 Álvaro Herrera
</pre>
15 6 Álvaro Herrera
16 8 Álvaro Herrera
Note that for *8.3* you need this instead:
17
<pre>
18 6 Álvaro Herrera
INSERT INTO pg_pltemplate VALUES
19
('plphp', 't', 't', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp', NULL);
20
21
INSERT INTO pg_pltemplate VALUES
22 1 Álvaro Herrera
('plphpu', 'f', 't', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp', NULL);
23 8 Álvaro Herrera
</pre>
24 5 Álvaro Herrera
25 8 Álvaro Herrera
Note you *DON'T* have to edit the @$libdir@.  Leave it alone.  It will be expanded by [[PostgreSQL]] automatically.  You don't need to add the @.so@ suffix either (or whatever it's called on your platform.)
26 1 Álvaro Herrera
27
This will create entries for the trusted and untrusted versions of PL/php.  Note that pg_pltemplate is a shared catalog, which means you have to do it only once in any database and it will be available in all your databases automatically.
28
29
In any database where you want to use PL/php you need to issue simply
30
31 8 Álvaro Herrera
<pre>
32 1 Álvaro Herrera
CREATE LANGUAGE plphp;
33 8 Álvaro Herrera
</pre>
34 1 Álvaro Herrera
35
or
36 8 Álvaro Herrera
<pre>
37 1 Álvaro Herrera
CREATE LANGUAGE plphpu;
38 8 Álvaro Herrera
</pre>
39 2 Álvaro Herrera
(the latter will create the untrusted version, which by default only superusers can write functions in).
40 5 Álvaro Herrera
41 1 Álvaro Herrera
Now the language is ready to be used.
42
43
If you receive an error similar to:
44
45 8 Álvaro Herrera
<pre>
46 2 Álvaro Herrera
ERROR:  could not load library "/usr/local/lib/postgresql/plphp":
47 1 Álvaro Herrera
libphp4.so: cannot open shared object file: No such file or directory
48 8 Álvaro Herrera
</pre>
49 6 Álvaro Herrera
50 1 Álvaro Herrera
it means the Postmaster can't find the PHP shared library.  You should probably define a LD_LIBRARY_PATH variable in the postmaster environment that points to the location where libphp.so is located (or add that path to /etc/ld.so.conf)