<HTML ><HEAD ><TITLE >PostgreSQL functions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Function Reference" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="posix_uname" HREF="function.posix-uname.html"><LINK REL="NEXT" TITLE="pg_affected_rows" HREF="function.pg-affected-rows.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="reference" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.posix-uname.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.pg-affected-rows.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.pgsql" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >LXXXI. PostgreSQL functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN75959" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.intro" ></A >Introduction</H1 ><P > PostgreSQL database is Open Source product and available without cost. 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. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.requirements" ></A >Requirements</H1 ><P > To use PostgreSQL support, you need PostgreSQL 6.5 or later, PostgreSQL 7.0 or later to enable all PostgreSQL module features. PostgreSQL supports many character encoding including multibyte character encoding. The current version and more information about PostgreSQL is available at <A HREF="http://www.postgresql.org/" TARGET="_top" >http://www.postgresql.org/</A >. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.installation" ></A >Installation</H1 ><P > In order to enable PostgreSQL support, <TT CLASS="option" >--with-pgsql[=DIR]</TT > is required when you compile PHP. DIR is the PostgreSQL base install directory, defaults to <TT CLASS="filename" >/usr/local/pgsql</TT >. If shared object module is available, PostgreSQL module may be loaded using <A HREF="configuration.directives.html#ini.extension" >extension</A > directive in <TT CLASS="filename" >php.ini</TT > or <A HREF="function.dl.html" ><B CLASS="function" >dl()</B ></A > function. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.configuration" ></A >Runtime Configuration</H1 ><P > The behaviour of these functions is affected by settings in <TT CLASS="filename" >php.ini</TT >. </P ><P > <DIV CLASS="table" ><A NAME="AEN75980" ></A ><P ><B >Table 1. PostgreSQL configuration options</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Name</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Default</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Changeable</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >pgsql.allow_persistent</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"1"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >pgsql.max_persistent</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"-1"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >pgsql.max_links</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"-1"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >pgsql.auto_reset_persistent</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >pgsql.ignore_notice</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >pgsql.log_notice</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ></TBODY ></TABLE ></DIV > For further details and definition of the PHP_INI_* constants see <A HREF="function.ini-set.html" ><B CLASS="function" >ini_set()</B ></A >. </P ><P > Here is a short explanation of the configuration directives. <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.pgsql.allow-persistent" ></A ><TT CLASS="parameter" ><I >pgsql.allow_persistent</I ></TT > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P > Whether to allow persistent Postgres connections. </P ></DD ><DT ><A NAME="ini.pgsql.max-persistent" ></A ><TT CLASS="parameter" ><I >pgsql.max_persistent</I ></TT > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > The maximum number of persistent Postgres connections per process. </P ></DD ><DT ><A NAME="ini.pgsql.max-links" ></A ><TT CLASS="parameter" ><I >pgsql.max_links</I ></TT > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > The maximum number of Postgres connections per process, including persistent connections. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.using" ></A >How to use and hints</H1 ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Warning</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > 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. </P ></TD ></TR ></TABLE ></DIV ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Warning</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > 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. </P ><DIV CLASS="table" ><A NAME="AEN76040" ></A ><P ><B >Table 2. Function names changed</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Old name</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >New name</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_exec()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-query.html" ><B CLASS="function" >pg_query()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_getlastoid()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-last-oid.html" ><B CLASS="function" >pg_last_oid()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_cmdtuples()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-affected-rows.html" ><B CLASS="function" >pg_affected_rows()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_numrows()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-num-rows.html" ><B CLASS="function" >pg_num_rows()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_numfields()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-num-fields.html" ><B CLASS="function" >pg_num_fields()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_fieldname()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-field-name.html" ><B CLASS="function" >pg_field_name()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_fieldsize()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-field-size.html" ><B CLASS="function" >pg_field_size()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_fieldnum()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-field-num.html" ><B CLASS="function" >pg_field_num()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_fieldprtlen()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-field-prtlen.html" ><B CLASS="function" >pg_field_prtlen()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_fieldisnull()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-field-is-null.html" ><B CLASS="function" >pg_field_is_null()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_freeresult()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-free-result.html" ><B CLASS="function" >pg_free_result()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_result()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-fetch-result.html" ><B CLASS="function" >pg_fetch_result()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_loreadall()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-lo-read-all.html" ><B CLASS="function" >pg_lo_read_all()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_locreate()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-lo-create.html" ><B CLASS="function" >pg_lo_create()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_lounlink()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-lo-unlink.html" ><B CLASS="function" >pg_lo_unlink()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_loopen()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-lo-open.html" ><B CLASS="function" >pg_lo_open()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_loclose()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-lo-close.html" ><B CLASS="function" >pg_lo_close()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_loread()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-lo-read.html" ><B CLASS="function" >pg_lo_read()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_lowrite()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-lo-write.html" ><B CLASS="function" >pg_lo_write()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_loimport()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-lo-import.html" ><B CLASS="function" >pg_lo_import()</B ></A ></TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><B CLASS="function" >pg_loexport()</B ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><A HREF="function.pg-lo-export.html" ><B CLASS="function" >pg_lo_export()</B ></A ></TD ></TR ></TBODY ></TABLE ></DIV ><P > The old <A HREF="function.pg-connect.html" ><B CLASS="function" >pg_connect()</B ></A >/<A HREF="function.pg-pconnect.html" ><B CLASS="function" >pg_pconnect()</B ></A > syntax will be deprecated to support asynchronous connections in the future. Please use a connection string for <A HREF="function.pg-connect.html" ><B CLASS="function" >pg_connect()</B ></A > and <A HREF="function.pg-pconnect.html" ><B CLASS="function" >pg_pconnect()</B ></A >. </P ></TD ></TR ></TABLE ></DIV ><P > 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. </P ><P > It is also important that you do not use an older libpq than the PostgreSQL Server to which you will be connecting. If you use libpq older than PostgreSQL Server expects, you may have problems. </P ><P > 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 <TT CLASS="filename" >/tmp/.s.PGSQL.5432</TT >. This option can be enabled with the '-i' flag to <B CLASS="command" >postmaster</B > and it's meaning is: "listen on TCP/IP sockets as well as Unix domain sockets". <DIV CLASS="table" ><A NAME="AEN76163" ></A ><P ><B >Table 3. Postmaster and PHP</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Postmaster</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >PHP</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Status</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >postmaster &</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >pg_connect("dbname=MyDbName");</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >OK</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >postmaster -i &</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >pg_connect("dbname=MyDbName");</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >OK</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >postmaster &</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >pg_connect("host=localhost dbname=MyDbName");</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > 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. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >postmaster -i &</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >pg_connect("host=localhost dbname=MyDbName");</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >OK</TD ></TR ></TBODY ></TABLE ></DIV > </P ><P > A connection to PostgreSQL server can be established with the following value pairs set in the command string: <B CLASS="command" >$conn = pg_connect("host=myHost port=myPort tty=myTTY options=myOptions dbname=myDB user=myUser password=myPassword "); </B > </P ><P > The previous syntax of: <B CLASS="command" > $conn = pg_connect ("host", "port", "options", "tty", "dbname") </B > has been deprecated. </P ><P > 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. </P ><P > Make sure you set environment variables for appropriate user. Use <TT CLASS="literal" >$_ENV</TT > or <A HREF="function.getenv.html" ><B CLASS="function" >getenv()</B ></A > to check which environment variables are available to the current process. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN76196" ></A ><P ><B >Example 1. Setting default parameters</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >PGHOST=pgsql.example.com 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</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.constants" ></A >Predefined Constants</H1 ><P > The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime. </P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >PGSQL_ASSOC</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_NUM</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_BOTH</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_CONNECTION_BAD</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_CONNECTION_OK</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_SEEK_SET</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_SEEK_CUR</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_SEEK_END</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_ESCAPE_STRING</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_ESCAPE_BYTEA</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_EMPTY_QUERY</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_COMMAND_OK</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_TUPLES_OK</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_COPY_OUT</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_COPY_IN</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_BAD_RESPONSE</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_NONFATAL_ERROR</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_FATAL_ERROR</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.examples" ></A >Examples</H1 ><P > 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) </P ><P > 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 <B CLASS="command" >BEGIN</B > and if the transaction was valid ends with <B CLASS="command" >COMMIT</B > or <B CLASS="command" >END</B >. If the transaction fails the transaction should be closed with <B CLASS="command" >ROLLBACK</B > or <B CLASS="command" >ABORT</B >. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN76320" ></A ><P ><B >Example 2. Using Large Objects</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?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"); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > You should not close the connection to the PostgreSQL server before closing the large object. </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="function.pg-affected-rows.html" >pg_affected_rows</A > -- Returns number of affected records(tuples)</DT ><DT ><A HREF="function.pg-cancel-query.html" >pg_cancel_query</A > -- Cancel async query </DT ><DT ><A HREF="function.pg-client-encoding.html" >pg_client_encoding</A > -- Get the client encoding </DT ><DT ><A HREF="function.pg-close.html" >pg_close</A > -- Close a PostgreSQL connection</DT ><DT ><A HREF="function.pg-connect.html" >pg_connect</A > -- Open a PostgreSQL connection</DT ><DT ><A HREF="function.pg-connection-busy.html" >pg_connection_busy</A > -- Get connection is busy or not </DT ><DT ><A HREF="function.pg-connection-reset.html" >pg_connection_reset</A > -- Reset connection (reconnect) </DT ><DT ><A HREF="function.pg-connection-status.html" >pg_connection_status</A > -- Get connection status </DT ><DT ><A HREF="function.pg-convert.html" >pg_convert</A > -- Convert associative array value into suitable for SQL statement. </DT ><DT ><A HREF="function.pg-copy-from.html" >pg_copy_from</A > -- Insert records into a table from an array </DT ><DT ><A HREF="function.pg-copy-to.html" >pg_copy_to</A > -- Copy a table to an array </DT ><DT ><A HREF="function.pg-dbname.html" >pg_dbname</A > -- Get the database name</DT ><DT ><A HREF="function.pg-delete.html" >pg_delete</A > -- Delete records. </DT ><DT ><A HREF="function.pg-end-copy.html" >pg_end_copy</A > -- Sync with PostgreSQL backend</DT ><DT ><A HREF="function.pg-escape-bytea.html" >pg_escape_bytea</A > -- Escape binary for bytea type </DT ><DT ><A HREF="function.pg-escape-string.html" >pg_escape_string</A > -- Escape string for text/char type </DT ><DT ><A HREF="function.pg-fetch-all.html" >pg_fetch_all</A > -- Fetch a row as an array</DT ><DT ><A HREF="function.pg-fetch-array.html" >pg_fetch_array</A > -- Fetch a row as an array</DT ><DT ><A HREF="function.pg-fetch-assoc.html" >pg_fetch_assoc</A > -- Fetch a row as an array</DT ><DT ><A HREF="function.pg-fetch-object.html" >pg_fetch_object</A > -- Fetch a row as an object</DT ><DT ><A HREF="function.pg-fetch-result.html" >pg_fetch_result</A > -- Returns values from a result resource</DT ><DT ><A HREF="function.pg-fetch-row.html" >pg_fetch_row</A > -- Get a row as an enumerated array</DT ><DT ><A HREF="function.pg-field-is-null.html" >pg_field_is_null</A > -- Test if a field is <TT CLASS="constant" ><B >NULL</B ></TT ></DT ><DT ><A HREF="function.pg-field-name.html" >pg_field_name</A > -- Returns the name of a field</DT ><DT ><A HREF="function.pg-field-num.html" >pg_field_num</A > -- Returns the field number of the named field</DT ><DT ><A HREF="function.pg-field-prtlen.html" >pg_field_prtlen</A > -- Returns the printed length</DT ><DT ><A HREF="function.pg-field-size.html" >pg_field_size</A > -- Returns the internal storage size of the named field </DT ><DT ><A HREF="function.pg-field-type.html" >pg_field_type</A > -- Returns the type name for the corresponding field number </DT ><DT ><A HREF="function.pg-free-result.html" >pg_free_result</A > -- Free result memory</DT ><DT ><A HREF="function.pg-get-notify.html" >pg_get_notify</A > -- Ping database connection</DT ><DT ><A HREF="function.pg-get-pid.html" >pg_get_pid</A > -- Ping database connection</DT ><DT ><A HREF="function.pg-get-result.html" >pg_get_result</A > -- Get asynchronous query result </DT ><DT ><A HREF="function.pg-host.html" >pg_host</A > -- Returns the host name associated with the connection </DT ><DT ><A HREF="function.pg-insert.html" >pg_insert</A > -- Insert array into table. </DT ><DT ><A HREF="function.pg-last-error.html" >pg_last_error</A > -- Get the last error message string of a connection</DT ><DT ><A HREF="function.pg-last-notice.html" >pg_last_notice</A > -- Returns the last notice message from PostgreSQL server </DT ><DT ><A HREF="function.pg-last-oid.html" >pg_last_oid</A > -- Returns the last object's oid</DT ><DT ><A HREF="function.pg-lo-close.html" >pg_lo_close</A > -- Close a large object</DT ><DT ><A HREF="function.pg-lo-create.html" >pg_lo_create</A > -- Create a large object</DT ><DT ><A HREF="function.pg-lo-export.html" >pg_lo_export</A > -- Export a large object to file</DT ><DT ><A HREF="function.pg-lo-import.html" >pg_lo_import</A > -- Import a large object from file</DT ><DT ><A HREF="function.pg-lo-open.html" >pg_lo_open</A > -- Open a large object</DT ><DT ><A HREF="function.pg-lo-read-all.html" >pg_lo_read_all</A > -- Read a entire large object and send straight to browser </DT ><DT ><A HREF="function.pg-lo-read.html" >pg_lo_read</A > -- Read a large object</DT ><DT ><A HREF="function.pg-lo-seek.html" >pg_lo_seek</A > -- Seeks position of large object </DT ><DT ><A HREF="function.pg-lo-tell.html" >pg_lo_tell</A > -- Returns current position of large object </DT ><DT ><A HREF="function.pg-lo-unlink.html" >pg_lo_unlink</A > -- Delete a large object</DT ><DT ><A HREF="function.pg-lo-write.html" >pg_lo_write</A > -- Write a large object</DT ><DT ><A HREF="function.pg-meta-data.html" >pg_meta_data</A > -- Get meta data for table. </DT ><DT ><A HREF="function.pg-num-fields.html" >pg_num_fields</A > -- Returns the number of fields</DT ><DT ><A HREF="function.pg-num-rows.html" >pg_num_rows</A > -- Returns the number of rows</DT ><DT ><A HREF="function.pg-options.html" >pg_options</A > -- Get the options associated with the connection</DT ><DT ><A HREF="function.pg-pconnect.html" >pg_pconnect</A > -- Open a persistent PostgreSQL connection</DT ><DT ><A HREF="function.pg-ping.html" >pg_ping</A > -- Ping database connection</DT ><DT ><A HREF="function.pg-port.html" >pg_port</A > -- Return the port number associated with the connection </DT ><DT ><A HREF="function.pg-put-line.html" >pg_put_line</A > -- Send a NULL-terminated string to PostgreSQL backend</DT ><DT ><A HREF="function.pg-query.html" >pg_query</A > -- Execute a query</DT ><DT ><A HREF="function.pg-result-error.html" >pg_result_error</A > -- Get error message associated with result </DT ><DT ><A HREF="function.pg-result-seek.html" >pg_result_seek</A > -- Set internal row offset in result resource</DT ><DT ><A HREF="function.pg-result-status.html" >pg_result_status</A > -- Get status of query result </DT ><DT ><A HREF="function.pg-select.html" >pg_select</A > -- Select records. </DT ><DT ><A HREF="function.pg-send-query.html" >pg_send_query</A > -- Send asynchronous query </DT ><DT ><A HREF="function.pg-set-client-encoding.html" >pg_set_client_encoding</A > -- Set the client encoding </DT ><DT ><A HREF="function.pg-trace.html" >pg_trace</A > -- Enable tracing a PostgreSQL connection</DT ><DT ><A HREF="function.pg-tty.html" >pg_tty</A > -- Return the tty name associated with the connection </DT ><DT ><A HREF="function.pg-unescape-bytea.html" >pg_unescape_bytea</A > -- Escape binary for bytea type </DT ><DT ><A HREF="function.pg-untrace.html" >pg_untrace</A > -- Disable tracing of a PostgreSQL connection</DT ><DT ><A HREF="function.pg-update.html" >pg_update</A > -- Update table. </DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.posix-uname.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.pg-affected-rows.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >posix_uname</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >pg_affected_rows</TD ></TR ></TABLE ></DIV ></BODY ></HTML >