2002-04-15 00:12:54 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2002-05-20 20:00:45 +00:00
|
|
|
<!-- $Revision: 1.7 $ -->
|
2002-04-15 00:12:54 +00:00
|
|
|
<reference id="ref.pgsql">
|
2002-05-04 10:33:43 +00:00
|
|
|
<title>PostgreSQL functions</title>
|
2002-04-15 00:12:54 +00:00
|
|
|
<titleabbrev>PostgreSQL</titleabbrev>
|
|
|
|
|
|
|
|
<partintro>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
Postgres, developed originally in the UC Berkeley Computer Science
|
|
|
|
Department, pioneered many of the object-relational concepts now
|
|
|
|
becoming available in some commercial databases. It provides
|
|
|
|
SQL92/SQL99 language support, transaction integrity and type
|
|
|
|
extensibility. PostgreSQL is an open source descendant of this
|
|
|
|
original Berkeley code.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
PostgreSQL database is Open Source product and available without
|
|
|
|
cost. To use PostgreSQL support, you need PostgreSQL 6.5 or
|
|
|
|
later. PostgreSQL 7.0 or later to enable all PostgreSQL module
|
|
|
|
feature. PostgreSQL supports many character encoding including
|
|
|
|
multibyte character encoding. The current version and more
|
|
|
|
information about PostgreSQL is available at <ulink
|
|
|
|
url="&url.pgsql;">&url.pgsql;</ulink>.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
In order to enable PostgreSQL support,
|
|
|
|
<option role="configure">--with-pgsql[=DIR]</option> is required when you compile
|
|
|
|
PHP. If shared object module is available, PostgreSQL module may
|
|
|
|
be loaded using <link linkend="ini.extension">extension</link>
|
|
|
|
directive in &php.ini; or <function>dl</function>
|
|
|
|
function. Supported ini directives are described in
|
|
|
|
<filename>php.ini-dist</filename> which comes with source distribution.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<warning>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
Using the PostgreSQL module with PHP 4.0.6 is not recommended due to
|
|
|
|
a bug in the notice message handling code. Use 4.1.0 or later.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
</warning>
|
|
|
|
<warning>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
PostgreSQL function names will be changed in 4.2.0 release to
|
|
|
|
confirm to current coding standards. Most of new names will have
|
|
|
|
additional underscores, e.g. pg_lo_open(). Some functions are
|
|
|
|
renamed to different name for consistency. e.g. pg_exec() to
|
|
|
|
pg_query(). Older names can be used in 4.2.0 and a few releases
|
|
|
|
from 4.2.0, but they may be deleted in the future.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<table>
|
2002-05-04 10:33:43 +00:00
|
|
|
<title>Function names changed</title>
|
2002-04-15 00:12:54 +00:00
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
2002-05-04 10:33:43 +00:00
|
|
|
<entry>Old name</entry>
|
|
|
|
<entry>New name</entry>
|
2002-04-15 00:12:54 +00:00
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_exec</function></entry>
|
|
|
|
<entry><function>pg_query</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_getlastoid</function></entry>
|
|
|
|
<entry><function>pg_last_oid</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_cmdtuples</function></entry>
|
|
|
|
<entry><function>pg_affected_rows</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_numrows</function></entry>
|
|
|
|
<entry><function>pg_num_rows</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_numfields</function></entry>
|
|
|
|
<entry><function>pg_num_fields</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_fieldname</function></entry>
|
|
|
|
<entry><function>pg_field_name</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_fieldsize</function></entry>
|
|
|
|
<entry><function>pg_field_size</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_fieldnum</function></entry>
|
|
|
|
<entry><function>pg_field_num</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
2002-04-25 00:16:22 +00:00
|
|
|
<entry><function>pg_fieldprtlen</function></entry>
|
|
|
|
<entry><function>pg_field_prtlen</function></entry>
|
2002-04-15 00:12:54 +00:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_fieldisnull</function></entry>
|
|
|
|
<entry><function>pg_field_is_null</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_freeresult</function></entry>
|
|
|
|
<entry><function>pg_free_result</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_result</function></entry>
|
|
|
|
<entry><function>pg_fetch_result</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_loreadall</function></entry>
|
|
|
|
<entry><function>pg_lo_read_all</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_locreate</function></entry>
|
|
|
|
<entry><function>pg_lo_create</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_lounlink</function></entry>
|
|
|
|
<entry><function>pg_lo_unlink</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_loopen</function></entry>
|
2002-05-09 08:27:48 +00:00
|
|
|
<entry><function>pg_lo_open</function></entry>
|
2002-04-15 00:12:54 +00:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_loclose</function></entry>
|
|
|
|
<entry><function>pg_lo_close</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_loread</function></entry>
|
|
|
|
<entry><function>pg_lo_read</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_lowrite</function></entry>
|
|
|
|
<entry><function>pg_lo_write</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_loimport</function></entry>
|
|
|
|
<entry><function>pg_lo_import</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_loexport</function></entry>
|
|
|
|
<entry><function>pg_lo_export</function></entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
The old <function>pg_connect</function>/<function>pg_pconnect</function>
|
|
|
|
syntax will be deprecated to support asynchronous connections in the
|
|
|
|
future. Please use a connection string for <function>pg_connect</function>
|
|
|
|
and <function>pg_pconnect</function>.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
</warning>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
Not all functions are supported by all builds. It depends on your
|
|
|
|
libpq (The PostgreSQL C Client interface) version and how libpq is
|
|
|
|
compiled. If there is missing function, libpq does not support
|
|
|
|
the feature required for the function.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
It is also important that you use newer libpq than PostgreSQL
|
|
|
|
Server to be connected. If you use libpq older than PostgreSQL
|
|
|
|
Server expects, you may have problems.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
Since version 6.3 (03/02/1998) PostgreSQL uses unix domain sockets
|
|
|
|
by default. TCP port will NOT be opened by default. A table is
|
|
|
|
shown below describing these new connection possibilities. This
|
|
|
|
socket will be found in <filename>/tmp/.s.PGSQL.5432</filename>.
|
|
|
|
This option can be enabled with the '-i' flag to
|
|
|
|
<command>postmaster</command> and it's meaning is: "listen on
|
|
|
|
TCP/IP sockets as well as Unix domain sockets".
|
2002-04-15 00:12:54 +00:00
|
|
|
<table>
|
2002-05-04 10:33:43 +00:00
|
|
|
<title>Postmaster and PHP</title>
|
2002-04-15 00:12:54 +00:00
|
|
|
<tgroup cols="3">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>Postmaster</entry>
|
|
|
|
<entry>PHP</entry>
|
|
|
|
<entry>Status</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>postmaster &</entry>
|
|
|
|
<entry>pg_connect("dbname=MyDbName");</entry>
|
|
|
|
<entry>OK</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>postmaster -i &</entry>
|
|
|
|
<entry>pg_connect("dbname=MyDbName");</entry>
|
|
|
|
<entry>OK</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>postmaster &</entry>
|
|
|
|
<entry>pg_connect("host=localhost dbname=MyDbName");</entry>
|
|
|
|
<entry>
|
|
|
|
Unable to connect to PostgreSQL server: connectDB() failed:
|
|
|
|
Is the postmaster running and accepting TCP/IP (with -i)
|
|
|
|
connection at 'localhost' on port '5432'? in
|
|
|
|
/path/to/file.php on line 20.
|
|
|
|
</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>postmaster -i &</entry>
|
|
|
|
<entry>pg_connect("host=localhost dbname=MyDbName");</entry>
|
|
|
|
<entry>OK</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
</para>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
A connection to PostgreSQL server can be established with the
|
|
|
|
following value pairs set in the command string: <command>$conn =
|
|
|
|
pg_connect("host=myHost port=myPort tty=myTTY options=myOptions
|
|
|
|
dbname=myDB user=myUser password=myPassword ");
|
2002-04-15 00:12:54 +00:00
|
|
|
</command>
|
|
|
|
</para>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
The previous syntax of:
|
2002-04-15 00:12:54 +00:00
|
|
|
<command>
|
2002-05-04 10:33:43 +00:00
|
|
|
$conn = pg_connect ("host", "port", "options", "tty", "dbname")
|
2002-04-15 00:12:54 +00:00
|
|
|
</command>
|
2002-05-04 10:33:43 +00:00
|
|
|
has been deprecated.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
Environmental variables affect PostgreSQL server/client
|
|
|
|
behavior. For example, PostgreSQL module will lookup PGHOST
|
|
|
|
environment variable when the hostname is omitted in the connection
|
|
|
|
string. Supported environment variables are different from version
|
|
|
|
to version. Refer to PostgreSQL Programmer's Manual (libpq -
|
|
|
|
Environment Variables) for details.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
Make sure you set environment variables for appropriate user. Use
|
|
|
|
<literal>$_ENV</literal> or <function>getenv</function> to check
|
|
|
|
which environment variables are available to the current process.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<example>
|
2002-05-04 10:33:43 +00:00
|
|
|
<title>Setting default parameters</title>
|
2002-04-15 00:12:54 +00:00
|
|
|
<programlisting>
|
|
|
|
<![CDATA[
|
2002-05-20 20:00:45 +00:00
|
|
|
PGHOST=pgsql.example.com
|
2002-04-15 00:12:54 +00:00
|
|
|
PGPORT=7890
|
|
|
|
PGDATABASE=web-system
|
|
|
|
PGUSER=web-user
|
|
|
|
PGPASSWORD=secret
|
|
|
|
PGDATESTYLE=ISO
|
|
|
|
PGTZ=JST
|
|
|
|
PGCLIENTENCODING=EUC-JP
|
|
|
|
|
|
|
|
export PGHOST PGPORT PGDATABASE PGUSER PGPASSWORD PGDATESTYLE PGTZ PGCLIENTENCODING
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
Starting with PostgreSQL 7.1.0, you can store up to 1GB into a
|
|
|
|
field of type text. In older versions, this was limited to the block
|
|
|
|
size (default was 8KB, maximum was 32KB, defined at compile time)
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
To use the large object (lo) interface, it is required to enclose
|
|
|
|
large object functions within a transaction block. A transaction
|
|
|
|
block starts with a SQL statement <command>BEGIN</command> and if
|
|
|
|
the transaction was valid ends with <command>COMMIT</command> or
|
|
|
|
<command>END</command>. If the transaction fails the transaction
|
|
|
|
should be closed with <command>ROLLBACK</command> or
|
|
|
|
<command>ABORT</command>.
|
|
|
|
<example>
|
|
|
|
<title>Using Large Objects</title>
|
2002-04-15 00:12:54 +00:00
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
$database = pg_connect ("dbname=jacarta");
|
|
|
|
pg_query ($database, "begin");
|
|
|
|
$oid = pg_lo_create ($database);
|
|
|
|
echo "$oid\n";
|
|
|
|
$handle = pg_lo_open ($database, $oid, "w");
|
|
|
|
echo "$handle\n";
|
|
|
|
pg_lo_write ($handle, "large object data");
|
|
|
|
pg_lo_close ($handle);
|
|
|
|
pg_query ($database, "commit");
|
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
2002-05-04 10:33:43 +00:00
|
|
|
You should not close the connection to the PostgreSQL server
|
|
|
|
before closing the large object.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
</partintro>
|
|
|
|
|
|
|
|
&reference.pgsql.functions;
|
|
|
|
|
|
|
|
</reference>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
sgml-parent-document:nil
|
|
|
|
sgml-default-dtd-file:"../../../manual.ced"
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|