XLIV. PostgreSQL functions

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/SQL3 language support, transaction integrity, and type extensibility. PostgreSQL is a public-domain, open source descendant of this original Berkeley code.

PostgreSQL is available without cost. The current version is available at www.PostgreSQL.org.

Since version 6.3 (03/02/1998) PostgreSQL use unix domain sockets, a table is given to this new possibilities. This socket will be found in /tmp/.s.PGSQL.5432. This option can be enabled with the '-i' flag to postmaster and it's meaning is: "listen on TCP/IP sockets as well as Unix domain socket".

Table 1. Postmaster and PHP

PostmasterPHPStatus
postmaster &pg_connect("", "", "", "", "dbname");OK
postmaster -i &pg_connect("", "", "", "", "dbname");OK
postmaster &pg_connect("localhost", "", "", "", "dbname");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.php3 on line 20.
postmaster -i &pg_connect("localhost", "", "", "", "dbname");OK

One can also establish a connection with the following command: $conn = pg_Connect("host=localhost port=5432 dbname=chris");

To use the large object (lo) interface, it is necessary to enclose it within a transaction block. A transaction block starts with a begin and if the transaction was valid ends with commit and end. If the transaction fails the transaction should be closed with abort and rollback.

Example 1. Using Large Objects

<?php
$database = pg_Connect ("", "", "", "", "jacarta");
pg_exec ($database, "begin");
    $oid = pg_locreate ($database);
    echo ("$oid\n");
    $handle = pg_loopen ($database, $oid, "w");
    echo ("$handle\n");
    pg_lowrite ($handle, "gaga");
    pg_loclose ($handle);
pg_exec ($database, "commit")
pg_exec ($database, "end")
?>

Table of Contents
pg_Close — closes a PostgreSQL connection
pg_cmdTuples — returns number of affected tuples
pg_Connect — opens a connection
pg_DBname — database name
pg_ErrorMessage — error message
pg_Exec — execute a query
pg_Fetch_Array — fetch row as array
pg_Fetch_Object — fetch row as object
pg_Fetch_Row — get row as enumerated array
pg_FieldIsNull — Test if a field is NULL
pg_FieldName — Returns the name of a field
pg_FieldNum — Returns the number of a column
pg_FieldPrtLen — Returns the printed length
pg_FieldSize — Returns the internal storage size of the named field
pg_FieldType — Returns the type name for the corresponding field number
pg_FreeResult — Frees up memory
pg_GetLastOid — Returns the last object identifier
pg_Host — Returns the host name
pg_loclose — close a large object
pg_locreate — create a large object
pg_loopen — open a large object
pg_loread — read a large object
pg_loreadall — read a entire large object
pg_lounlink — delete a large object
pg_lowrite — write a large object
pg_NumFields — Returns the number of fields
pg_NumRows — Returns the number of rows
pg_Options — Returns options
pg_pConnect — make a persistent database connection
pg_Port — Returns the port number
pg_Result — Returns values from a result identifier
pg_tty — Returns the tty name