<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >PostgreSQL Functions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Manual PHP" HREF="index.html"><LINK REL="UP" TITLE="Documentaþia funcþiilor" 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-2"></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" >Manual PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.posix-uname.html" ACCESSKEY="P" >Înapoi</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" >Înainte</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.pgsql" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >LXXXVII. PostgreSQL Functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN93714" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.intro" >Introducere</A ></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, transactions, referential integrity, stored procedures 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" >Necesitãþi</A ></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 > and <A HREF="http://techdocs.postgresql.org/" TARGET="_top" >http://techdocs.postgresql.org/</A >. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.installation" >Instalare</A ></H1 ><P > In order to enable PostgreSQL support, <VAR CLASS="option" >--with-pgsql[=DIR]</VAR > 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="ini.sect.path-directory.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" >Configurare la rulare</A ></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="AEN93736" ></A ><P ><B >Tabel 1. PostgreSQL configuration options</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><THEAD ><TR ><TH >Name</TH ><TH >Default</TH ><TH >Changeable</TH ></TR ></THEAD ><TBODY ><TR ><TD >pgsql.allow_persistent</TD ><TD >"1"</TD ><TD >PHP_INI_SYSTEM</TD ></TR ><TR ><TD >pgsql.max_persistent</TD ><TD >"-1"</TD ><TD >PHP_INI_SYSTEM</TD ></TR ><TR ><TD >pgsql.max_links</TD ><TD >"-1"</TD ><TD >PHP_INI_SYSTEM</TD ></TR ><TR ><TD >pgsql.auto_reset_persistent</TD ><TD >"0"</TD ><TD >PHP_INI_SYSTEM</TD ></TR ><TR ><TD >pgsql.ignore_notice</TD ><TD >"0"</TD ><TD >PHP_INI_ALL</TD ></TR ><TR ><TD >pgsql.log_notice</TD ><TD >"0"</TD ><TD >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's a short explanation of the configuration directives.</P ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.pgsql.allow-persistent" ></A ><VAR CLASS="parameter" >pgsql.allow_persistent</VAR > <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 ><VAR CLASS="parameter" >pgsql.max_persistent</VAR > <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 ><VAR CLASS="parameter" >pgsql.max_links</VAR > <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 ><DT ><A NAME="ini.pgsql.auto-reset-persistent" ></A ><VAR CLASS="parameter" >pgsql.auto_reset_persistent</VAR > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > Detect broken persistent links with <A HREF="function.pg-pconnect.html" ><B CLASS="function" >pg_pconnect()</B ></A >. Needs a little overhead. </P ></DD ><DT ><A NAME="ini.pgsql.ignore-notice" ></A ><VAR CLASS="parameter" >pgsql.ignore_notice</VAR > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > Whether or not to ignore PostgreSQL backend notices. </P ></DD ><DT ><A NAME="ini.pgsql.log-notice" ></A ><VAR CLASS="parameter" >pgsql.log_notice</VAR > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > Whether or not to log PostgreSQL backends notice messages. The PHP directive <A HREF="ref.pgsql.html#ini.pgsql.ignore-notice" > pgsql.ignore_notice</A > must be off in order to log notice messages. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.using" >How to use and hints</A ></H1 ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Avertisment</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 >Avertisment</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="AEN93817" ></A ><P ><B >Tabel 2. Function names changed</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><THEAD ><TR ><TH >Old name</TH ><TH >New name</TH ></TR ></THEAD ><TBODY ><TR ><TD ><B CLASS="function" >pg_cmdtuples()</B ></TD ><TD ><A HREF="function.pg-affected-rows.html" ><B CLASS="function" >pg_affected_rows()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_errormessage()</B ></TD ><TD ><A HREF="function.pg-last-error.html" ><B CLASS="function" >pg_last_error()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_exec()</B ></TD ><TD ><A HREF="function.pg-query.html" ><B CLASS="function" >pg_query()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_fieldname()</B ></TD ><TD ><A HREF="function.pg-field-name.html" ><B CLASS="function" >pg_field_name()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_fieldsize()</B ></TD ><TD ><A HREF="function.pg-field-size.html" ><B CLASS="function" >pg_field_size()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_fieldnum()</B ></TD ><TD ><A HREF="function.pg-field-num.html" ><B CLASS="function" >pg_field_num()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_fieldprtlen()</B ></TD ><TD ><A HREF="function.pg-field-prtlen.html" ><B CLASS="function" >pg_field_prtlen()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_fieldisnull()</B ></TD ><TD ><A HREF="function.pg-field-is-null.html" ><B CLASS="function" >pg_field_is_null()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_freeresult()</B ></TD ><TD ><A HREF="function.pg-free-result.html" ><B CLASS="function" >pg_free_result()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_getlastoid()</B ></TD ><TD ><A HREF="function.pg-last-oid.html" ><B CLASS="function" >pg_last_oid()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_loreadall()</B ></TD ><TD ><A HREF="function.pg-lo-read-all.html" ><B CLASS="function" >pg_lo_read_all()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_locreate()</B ></TD ><TD ><A HREF="function.pg-lo-create.html" ><B CLASS="function" >pg_lo_create()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_lounlink()</B ></TD ><TD ><A HREF="function.pg-lo-unlink.html" ><B CLASS="function" >pg_lo_unlink()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_loopen()</B ></TD ><TD ><A HREF="function.pg-lo-open.html" ><B CLASS="function" >pg_lo_open()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_loclose()</B ></TD ><TD ><A HREF="function.pg-lo-close.html" ><B CLASS="function" >pg_lo_close()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_loread()</B ></TD ><TD ><A HREF="function.pg-lo-read.html" ><B CLASS="function" >pg_lo_read()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_lowrite()</B ></TD ><TD ><A HREF="function.pg-lo-write.html" ><B CLASS="function" >pg_lo_write()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_loimport()</B ></TD ><TD ><A HREF="function.pg-lo-import.html" ><B CLASS="function" >pg_lo_import()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_loexport()</B ></TD ><TD ><A HREF="function.pg-lo-export.html" ><B CLASS="function" >pg_lo_export()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_numrows()</B ></TD ><TD ><A HREF="function.pg-num-rows.html" ><B CLASS="function" >pg_num_rows()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_numfields()</B ></TD ><TD ><A HREF="function.pg-num-fields.html" ><B CLASS="function" >pg_num_fields()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_result()</B ></TD ><TD ><A HREF="function.pg-fetch-result.html" ><B CLASS="function" >pg_fetch_result()</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 its meaning is: "listen on TCP/IP sockets as well as Unix domain sockets". <DIV CLASS="table" ><A NAME="AEN93945" ></A ><P ><B >Tabel 3. Postmaster and PHP</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><THEAD ><TR ><TH >Postmaster</TH ><TH >PHP</TH ><TH >Status</TH ></TR ></THEAD ><TBODY ><TR ><TD >postmaster &</TD ><TD >pg_connect("dbname=MyDbName");</TD ><TD >OK</TD ></TR ><TR ><TD >postmaster -i &</TD ><TD >pg_connect("dbname=MyDbName");</TD ><TD >OK</TD ></TR ><TR ><TD >postmaster &</TD ><TD >pg_connect("host=localhost dbname=MyDbName");</TD ><TD > 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 >postmaster -i &</TD ><TD >pg_connect("host=localhost dbname=MyDbName");</TD ><TD >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 <VAR CLASS="literal" >$_ENV</VAR > 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="AEN93978" ></A ><P ><B >Exemplu 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 CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Notã: </B > PostgreSQL automatically folds all identifiers (e.g. table/column names) to lower-case values. To get it to recognize upper-case values, you must always wrap the identifier in quotes. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.constants" >Constante predefinite</A ></H1 ><P > Aceste constante sunt definite de aceastã extensie ºi vor fi disponibile doar cînd extensia a fost fie compilatã odatã la instalarea PHP fie dacã extensia este încãrcatã dinamic la rulare.</P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >PGSQL_ASSOC</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_NUM</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_BOTH</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_CONNECTION_BAD</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_CONNECTION_OK</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_SEEK_SET</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_SEEK_CUR</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_SEEK_END</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_ESCAPE_STRING</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_ESCAPE_BYTEA</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_EMPTY_QUERY</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_COMMAND_OK</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_TUPLES_OK</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_COPY_OUT</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_COPY_IN</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_BAD_RESPONSE</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_NONFATAL_ERROR</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_FATAL_ERROR</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.examples" >Exemple</A ></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="AEN94104" ></A ><P ><B >Exemplu 2. Using Large Objects</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /> $database </font><font color="#007700">= </font><font color="#0000BB">pg_connect</font><font color="#007700">(</font><font color="#DD0000">"dbname=jacarta"</font><font color="#007700">);<br /> </font><font color="#0000BB">pg_query</font><font color="#007700">(</font><font color="#0000BB">$database</font><font color="#007700">, </font><font color="#DD0000">"begin"</font><font color="#007700">);<br /> </font><font color="#0000BB">$oid </font><font color="#007700">= </font><font color="#0000BB">pg_lo_create</font><font color="#007700">(</font><font color="#0000BB">$database</font><font color="#007700">);<br /> echo </font><font color="#DD0000">"$oid</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">;<br /> </font><font color="#0000BB">$handle </font><font color="#007700">= </font><font color="#0000BB">pg_lo_open</font><font color="#007700">(</font><font color="#0000BB">$database</font><font color="#007700">, </font><font color="#0000BB">$oid</font><font color="#007700">, </font><font color="#DD0000">"w"</font><font color="#007700">);<br /> echo </font><font color="#DD0000">"$handle</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">;<br /> </font><font color="#0000BB">pg_lo_write</font><font color="#007700">(</font><font color="#0000BB">$handle</font><font color="#007700">, </font><font color="#DD0000">"large object data"</font><font color="#007700">);<br /> </font><font color="#0000BB">pg_lo_close</font><font color="#007700">(</font><font color="#0000BB">$handle</font><font color="#007700">);<br /> </font><font color="#0000BB">pg_query</font><font color="#007700">(</font><font color="#0000BB">$database</font><font color="#007700">, </font><font color="#DD0000">"commit"</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></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 >Cuprins</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 asynchronous query </DT ><DT ><A HREF="function.pg-client-encoding.html" >pg_client_encoding</A > -- Gets the client encoding </DT ><DT ><A HREF="function.pg-close.html" >pg_close</A > -- Closes 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 > -- Deletes 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 > -- Fetches all rows from a result 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 associative 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 > -- Reads an 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-parameter-status.html" >pg_parameter_status</A > -- Returns the value of a server parameter </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 > -- Sends 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 > -- Unescape 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 ><DT ><A HREF="function.pg-version.html" >pg_version</A > -- Returns an array with client, protocol and server version (when available) </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" >Înapoi</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Acasã</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.pg-affected-rows.html" ACCESSKEY="N" >Înainte</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" >Sus</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >pg_affected_rows</TD ></TR ></TABLE ></DIV ></BODY ></HTML >