Javascript debugger
Website design
↑
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.
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 encodings including multibyte character encoding. The current version and more information about PostgreSQL is available at » http://www.postgresql.org/ and the » PostgreSQL Documentation.
In order to enable PostgreSQL support,
--with-pgsql[=DIR]
is required when you compile
PHP. DIR is the PostgreSQL base install directory, defaults to
/usr/local/pgsql
. If shared object module is
available, PostgreSQL module may be loaded using
extension directive in php.ini
or
dl()
function.
The behaviour of these functions is affected by settings in php.ini
.
Name | Default | Changeable | Changelog |
---|---|---|---|
pgsql.allow_persistent | "1" | PHP_INI_SYSTEM | |
pgsql.max_persistent | "-1" | PHP_INI_SYSTEM | |
pgsql.max_links | "-1" | PHP_INI_SYSTEM | |
pgsql.auto_reset_persistent | "0" | PHP_INI_SYSTEM | Available since PHP 4.2.0. |
pgsql.ignore_notice | "0" | PHP_INI_ALL | Available since PHP 4.3.0. |
pgsql.log_notice | "0" | PHP_INI_ALL | Available since PHP 4.3.0. |
For further details and definitions of the
PHP_INI_* constants, see the Appendix I, php.ini
directives.
Here's a short explanation of the configuration directives.
Whether to allow persistent Postgres connections.
The maximum number of persistent Postgres connections per process.
The maximum number of Postgres connections per process, including persistent connections.
Detect broken persistent links with pg_pconnect(). Needs a little overhead.
Whether or not to ignore PostgreSQL backend notices.
Whether or not to log PostgreSQL backends notice messages. The PHP directive pgsql.ignore_notice must be off in order to log notice messages.
There are two resource types used in the PostgreSQL module. The first one is the link identifier for a database connection, the second a resource which holds the result of a query.
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.
PGSQL_ASSOC
(integer)
PGSQL_NUM
(integer)
PGSQL_BOTH
(integer)
PGSQL_CONNECT_FORCE_NEW
(integer)
PGSQL_CONNECTION_BAD
(integer)
PGSQL_CONNECTION_OK
(integer)
PGSQL_SEEK_SET
(integer)
PGSQL_SEEK_CUR
(integer)
PGSQL_SEEK_END
(integer)
PGSQL_EMPTY_QUERY
(integer)
PGSQL_COMMAND_OK
(integer)
PGSQL_TUPLES_OK
(integer)
SELECT
or SHOW
).
PGSQL_COPY_OUT
(integer)
PGSQL_COPY_IN
(integer)
PGSQL_BAD_RESPONSE
(integer)
PGSQL_NONFATAL_ERROR
(integer)
PGSQL_FATAL_ERROR
(integer)
PGSQL_TRANSACTION_IDLE
(integer)
PGSQL_TRANSACTION_ACTIVE
(integer)
PGSQL_TRANSACTION_INTRANS
(integer)
PGSQL_TRANSACTION_INERROR
(integer)
PGSQL_TRANSACTION_UNKNOWN
(integer)
PGSQL_DIAG_SEVERITY
(integer)
ERROR
,
FATAL
, or PANIC
(in an error message), or
WARNING
, NOTICE
, DEBUG
,
INFO
, or LOG
(in a notice message), or a localized
translation of one of these. Always present.
PGSQL_DIAG_SQLSTATE
(integer)
PGSQL_DIAG_MESSAGE_PRIMARY
(integer)
PGSQL_DIAG_MESSAGE_DETAIL
(integer)
PGSQL_DIAG_MESSAGE_HINT
(integer)
PGSQL_DIAG_STATEMENT_POSITION
(integer)
PGSQL_DIAG_INTERNAL_POSITION
(integer)
PG_DIAG_STATEMENT_POSITION
field, but
it is used when the cursor position refers to an internally generated
command rather than the one submitted by the client. The
PG_DIAG_INTERNAL_QUERY
field will always appear when this
field appears.
PGSQL_DIAG_INTERNAL_QUERY
(integer)
PGSQL_DIAG_CONTEXT
(integer)
PGSQL_DIAG_SOURCE_FILE
(integer)
PGSQL_DIAG_SOURCE_LINE
(integer)
PGSQL_DIAG_SOURCE_FUNCTION
(integer)
PGSQL_ERRORS_TERSE
(integer)
PGSQL_ERRORS_DEFAULT
(integer)
PGSQL_ERRORS_VERBOSE
(integer)
PGSQL_STATUS_LONG
(integer)
PGSQL_STATUS_STRING
(integer)
PGSQL_CONV_IGNORE_DEFAULT
(integer)
PGSQL_CONV_FORCE_NULL
(integer)
NULL
in place of an empty string.
PGSQL_CONV_IGNORE_DEFAULT
(integer)
NULL
into SQL NOT NULL
columns.
Not all functions are supported by all builds. It depends on your libpq (The PostgreSQL C client library) version and how libpq is compiled. If PHP PostgreSQL extensions are missing, then it is because your libpq version does not support them.
Most PostgreSQL functions accept connection as
the first optional parameter. If it is not provided, the last opened
connection is used. If it doesn't exist, functions return FALSE
.
PostgreSQL automatically folds all identifiers (e.g. table/column names) to lower-case values at object creation time and at query time. To force the use of mixed or upper case identifiers, you must escape the identifier using double quotes ("").
PostgreSQL does not have special commands for fetching database schema
information (eg. all the tables in the current database). Instead, there
is a standard schema named information_schema
in
PostgreSQL 7.4 and above containing
system views with all the necessary information, in an easily
queryable form. See the » PostgreSQL Documentation
for full details.
This simple example shows how to connect, execute a query, print resulting rows and disconnect from a PostgreSQL database.
<?php
// Connecting, selecting database
$dbconn = pg_connect("host=localhost dbname=publishing user=www password=foo")
or die('Could not connect: ' . pg_last_error());
// Performing SQL query
$query = 'SELECT * FROM authors';
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
// Printing results in HTML
echo "<table>\n";
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
// Free resultset
pg_free_result($result);
// Closing connection
pg_close($dbconn);
?>
Table of Contents
NULL