<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.25 $ -->
<reference id="ref.pgsql">
 <title>PostgreSQL Functions</title>
 <titleabbrev>PostgreSQL</titleabbrev>

 <partintro>
  <section id="pgsql.intro">
   &reftitle.intro;
   <para>
    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.
   </para>
  </section>

  <section id="pgsql.requirements">
   &reftitle.required;
   <para>
    To use PostgreSQL support, you need PostgreSQL 6.5 or
    later, PostgreSQL 8.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 
    <ulink url="&url.pgsql;">&url.pgsql;</ulink> and
    the <ulink url="&url.pgsql.manual;">PostgreSQL Documentation</ulink>.
   </para>
  </section>

  &reference.pgsql.configure;

  &reference.pgsql.ini;

  <section id="pgsql.using">
   <title>How to use and hints</title>
   <warning>
    <para>
     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.
    </para>
   </warning>
   <warning>
    <para>
     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.
    </para>
   <table>
    <title>Function names changed</title>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>Old name</entry>
       <entry>New name</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry><function>pg_cmdtuples</function></entry>
       <entry><function>pg_affected_rows</function></entry>
      </row>
      <row>
       <entry><function>pg_errormessage</function></entry>
       <entry><function>pg_last_error</function></entry>
      </row>
      <row>
       <entry><function>pg_exec</function></entry>
       <entry><function>pg_query</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>
       <entry><function>pg_fieldprtlen</function></entry>
       <entry><function>pg_field_prtlen</function></entry>
      </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_getlastoid</function></entry>
       <entry><function>pg_last_oid</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>
       <entry><function>pg_lo_open</function></entry>
      </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>
      <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_result</function></entry>
       <entry><function>pg_fetch_result</function></entry>
      </row>
     </tbody>
    </tgroup>
   </table>
   <para>
    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>.
   </para>
  </warning>
  <para>
   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. 
  </para>
  <para>
   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.
  </para>
  <para>
   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 its meaning is: "listen on
   TCP/IP sockets as well as Unix domain sockets".
   <table>
    <title>Postmaster and PHP</title>
    <tgroup cols="3">
     <thead>
      <row>
       <entry>Postmaster</entry>
       <entry>PHP</entry>
       <entry>Status</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>postmaster &amp;</entry>
       <entry>pg_connect("dbname=MyDbName");</entry>
       <entry>OK</entry>
      </row>
      <row>
       <entry>postmaster -i &amp;</entry>
       <entry>pg_connect("dbname=MyDbName");</entry>
       <entry>OK</entry>
      </row>
      <row>
       <entry>postmaster &amp;</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 &amp;</entry>
       <entry>pg_connect("host=localhost dbname=MyDbName");</entry>
       <entry>OK</entry>
      </row>
     </tbody>
    </tgroup>
   </table>
  </para>
  <para>
   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 ");
   </command>
  </para>
  <para>
   The previous syntax of:
   <command>
    $conn = pg_connect ("host", "port", "options", "tty", "dbname")
   </command>
   has been deprecated.
  </para>
  <para>
   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.
  </para>
  <para>
   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.
  </para>
  <example>
   <title>Setting default parameters</title>
   <programlisting>
<![CDATA[
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
]]>
    </programlisting>
   </example>
   <note>
    <para>
     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.
    </para>
   </note>
  </section>

  &reference.pgsql.constants;

  <section id="pgsql.examples">
   &reftitle.examples;
   <para>
    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)
   </para>
   <para>
    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>
     <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>
    You should not close the connection to the PostgreSQL server
    before closing the large object.
   </para>
  </section>
 </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
-->