PostgreSQL functions PostgreSQL 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. PostgreSQL database is Open Source product and available without cost. To use PostgreSQL support, you need PostgreSQL 6.5 or later. PostgreSQL 7.0 or later to enable all PostgreSQL module feature. PostgreSQL supports many character encoding including multibyte character encoding. The current version and more information about PostgreSQL is available at &url.pgsql;. In order to enable PostgreSQL support, is required when you compile PHP. If shared object module is available, PostgreSQL module may be loaded using extension directive in &php.ini; or dl function. Supported ini directives are described in php.ini-dist which comes with source distribution. 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. 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. Function names changed Old name New name pg_exec pg_query pg_getlastoid pg_last_oid pg_cmdtuples pg_affected_rows pg_numrows pg_num_rows pg_numfields pg_num_fields pg_fieldname pg_field_name pg_fieldsize pg_field_size pg_fieldnum pg_field_num pg_fieldptrlen pg_field_ptrlen pg_fieldisnull pg_field_is_null pg_freeresult pg_free_result pg_result pg_fetch_result pg_loreadall pg_lo_read_all pg_locreate pg_lo_create pg_lounlink pg_lo_unlink pg_loopen pg_lo_unlink pg_loclose pg_lo_close pg_loread pg_lo_read pg_lowrite pg_lo_write pg_loimport pg_lo_import pg_loexport pg_lo_export
The old pg_connect/pg_pconnect syntax will be deprecated to support asynchronous connections in the future. Please use a connection string for pg_connect and pg_pconnect.
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. It is also important that you use newer libpq than PostgreSQL Server to be connected. If you use libpq older than PostgreSQL Server expects, you may have problems. 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 /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 sockets". Postmaster and PHP Postmaster PHP Status postmaster & pg_connect("dbname=MyDbName"); OK postmaster -i & pg_connect("dbname=MyDbName"); OK postmaster & pg_connect("host=localhost dbname=MyDbName"); 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. postmaster -i & pg_connect("host=localhost dbname=MyDbName"); OK
A connection to PostgreSQL server can be established with the following value pairs set in the command string: $conn = pg_connect("host=myHost port=myPort tty=myTTY options=myOptions dbname=myDB user=myUser password=myPassword "); The previous syntax of: $conn = pg_connect ("host", "port", "options", "tty", "dbname") has been deprecated. 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. Make sure you set environment variables for appropriate user. Use $_ENV or getenv to check which environment variables are available to the current process. Setting default parameters 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) 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 BEGIN and if the transaction was valid ends with COMMIT or END. If the transaction fails the transaction should be closed with ROLLBACK or ABORT. Using Large Objects ]]> You should not close the connection to the PostgreSQL server before closing the large object.
pg_affected_rows Returns number of affected records(tuples) Description intpg_affected_rows resourceresult pg_affected_rows returns the number of tuples (instances/records/rows) affected by INSERT, UPDATE, and DELETE queries executed by pg_query. If no tuple is affected by this function, it will return 0. <function>pg_affected_rows</function> ]]> This function used to be called pg_cmdtuples(). See also pg_query and pg_num_rows. pg_connect Open a PostgreSQL connection Description resourcepg_connect stringconnection_string pg_connect returns a connection resource that is needed by other PostgreSQL functions. pg_connect opens a connection to a PostgreSQL database specified by the connection_string. It returns a connection resource on success. It returns &false; if the connection could not be made. connection_string should be a quoted string. Using pg_connect ]]> The arguments available for connection_string includes host, port, tty, options, dbname, user, and password. If a second call is made to pg_connect with the same connection_string, no new connection will be established, but instead, the connection resource of the already opened connection will be returned. You can have multiple connections to the same database if you use different connection string. The old syntax with multiple parameters $conn = pg_connect ("host", "port", "options", "tty", "dbname") has been deprecated. See also pg_pconnect, pg_close, pg_host, pg_port, pg_tty, pg_options and pg_dbname. pg_pconnect Open a persistent PostgreSQL connection Description intpg_pconnect stringconnection_string pg_pconnect opens a connection to a PostgreSQL database. It returns a connection resource that is needed by other PostgreSQL functions. For a description of the connection_string parameter, see pg_connect. To enable persistent connection, the pgsql.allow_persistent &php.ini; directive must be set to "On" (which is the default). The maximum number of persistent connection can be defined with the pgsql.max_persistent &php.ini; directive (defaults to -1 for no limit). The total number of connections can be set with the pgsql.max_links &php.ini; directive. pg_close will not close persistent links generated by pg_pconnect. See also pg_connect. pg_connection_busy Get connection is busy or not Description boolpg_connection_busy resourceconnection pg_connection_busy returns &true; if the connection is busy. If it's is busy, a previous query is still executing. If pg_get_result is called, it will be blocked. See also pg_connection_status and pg_get_result pg_connection_reset Reset connection (reconnect) Description boolpg_connection_reset resourceconnection pg_connection_reset resets the connection. It is useful for error recovery. &return.success; See also pg_connect, pg_pconnect and pg_connection_status pg_connection_status Get connection status Description intpg_connection_status resourceconnection pg_connection_status returns a connection status. Possible statuses are PGSQL_CONNECTION_OK and PGSQL_CONNECTION_BAD. See also pg_connection_busy. pg_close Close a PostgreSQL connection Description boolpg_close resourceconnection pg_close closes the non-persistent connection to a PostgreSQL database associated with the given connection resource. &return.success; Using pg_close is not usually necessary, as non-persistent open connections are automatically closed at the end of the script. If there is open large object resource on the connection, do not close the connection before closing all large object resources. pg_copy_from Copy a table from an array Description intpg_copy_from intconnection stringtable_name arrayrows stringdelimiter stringnull_as pg_copy_from copies a table from an array. &return.success; See also pg_copy_to pg_copy_to Copy a table to an array Description intpg_copy_to intconnection stringtable_name stringdelimiter stringnull_as pg_copy_to copies a table to an array. The resulting array is returned. It returns &false; on failure. See also pg_copy_from pg_end_copy Sync with PostgreSQL backend Description boolpg_end_copy resourceconnection pg_end_copy syncs the PostgreSQL frontend (usually a web server process) with the PostgreSQL server after doing a copy operation performed by pg_put_line. pg_end_copy must be issued, otherwise the PostgreSQL server may get out of sync with the frontend and will report an error. &return.success; For further details and an example, see also pg_put_line. pg_put_line Send a NULL-terminated string to PostgreSQL backend Description boolpg_put_line resourceconnection stringdata pg_put_line sends a NULL-terminated string to the PostgreSQL backend server. This is useful for example for very high-speed inserting of data into a table, initiated by starting a PostgreSQL copy-operation. That final NULL-character is added automatically. &return.success; The application must explicitly send the two characters "\." on the last line to indicate to the backend that it has finished sending its data. See also pg_end_copy. High-speed insertion of data into a table ]]> pg_last_error Get the last error message string of a connection Description stringpg_last_error resourceconnection pg_last_error returns the last error message for given connection. Error messages may be overwritten by internal PostgreSQL(libpq) function calls. It may not return appropriate error message, if multiple errors are occured inside a PostgreSQL module function. Use pg_result_error, pg_result_status and pg_connection_status for better error handling. This function used to be called pg_errormessage(). See also pg_result_error. pg_last_notice Returns the last notice message from PostgreSQL server Description stringpg_last_notice resourceconnection pg_last_notice returns the last notice message from the PostgreSQL server specified by connection. The PostgreSQL server sends notice messages in several cases, e.g. if the transactions can't be continued. With pg_last_notice, you can avoid issuing useless queries, by checking whether the notice is related to the transaction or not. This function is EXPERIMENTAL and it is not fully implemented yet. pg_last_notice was added in PHP 4.0.6. However, PHP 4.0.6 has problem with notice message handling. Use of the PostgreSQL module with PHP 4.0.6 is not recommended even if you are not using pg_last_notice. This function is fully implemented in PHP 4.3.0. PHP earlier than PHP 4.3.0 ignores database connection parameter. Notice message tracking can be set to optional by setting 1 for pgsql.ignore_notice ini from PHP 4.3.0. Notice message logging can be set to optional by setting 0 for pgsql.log_notice ini from PHP 4.3.0. Unless pgsql.ignore_notice is set to 0, notice message cannot be logged. See also pg_query and pg_last_error. pg_last_oid Returns the last object's oid Description intpg_last_oid resourceresult pg_last_oid is used to retrieve the oid assigned to an inserted tuple (record) if the result resource is used from the last command sent via pg_query and was an SQL INSERT. Returns a positive integer if there was a valid oid. It returns &false; if an error occurs or the last command sent via pg_query was not an INSERT or INSERT is failed. This function used to be called pg_getlastoid(). See also pg_query. pg_query Execute a query Description resourcepg_query resourceconnection stringquery pg_query returns a query result resource if query could be executed. It returns &false; on failure or if connection is not a valid connection. Details about the error can be retrieved using the pg_last_error function if connection is valid. pg_last_error sends an SQL statement to the PostgreSQL database specified by the connection resource. The connection must be a valid connection that was returned by pg_connect or pg_pconnect. The return value of this function is an query result resource to be used to access the results from other PostgreSQL functions such as pg_fetch_array. connection is a optional parameter for pg_query. If connection is not set, default connection is used. Default connection is the last connection made by pg_connect or pg_pconnect. Although connection can be omitted, it is not recommended, since it could be a cause of hard to find bug in script. This function used to be called pg_exec(). See also pg_connect, pg_pconnect, pg_fetch_array, pg_fetch_object, pg_num_rows, and pg_affected_rows. pg_fetch_array Fetch a row as an array Description arraypg_fetch_array resourceresult introw intresult_type pg_fetch_array returns an array that corresponds to the fetched row (tuples/records). It returns &false;, if there are no more rows. pg_fetch_array is an extended version of pg_fetch_row. In addition to storing the data in the numeric indices (field index) to the result array, it also stores the data in associative indices (field name) by default. row is row (record) number to be retrieved. First row is 0. result_type is optional parameter controls how return value is initialized. result_type is a constant and can take the following values: PGSQL_ASSOC, PGSQL_NUM, and PGSQL_BOTH. pg_fetch_array returns associative array that has field name as key for PGSQL_ASSOC. field index as key with PGSQL_NUM and both field name/index as key with PGSQL_BOTH. Default is PGSQL_BOTH. result_type was added in PHP 4.0. pg_fetch_array is NOT significantly slower than using pg_fetch_row, while it provides a significant ease of use. See also pg_fetch_row and pg_fetch_object and pg_fetch_result. PostgreSQL fetch array ]]> From 4.1.0, row became optional. pg_fetch_object Fetch a row as an object Description objectpg_fetch_object resourceresult introw intresult_type pg_fetch_object returns an object with properties that correspond to the fetched row. It returns &false; if there are no more rows or error. pg_fetch_object is similar to pg_fetch_array, with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names). result_type is optional parameter controls how return value is initialized. result_type is a constant and can take the following values: PGSQL_ASSOC, PGSQL_NUM, and PGSQL_BOTH. pg_fetch_array returns associative array that has field name as key for PGSQL_ASSOC. field index as key with PGSQL_NUM and both field name/index as key with PGSQL_BOTH. Default is PGSQL_BOTH. result_type was added in PHP 4.0. Speed-wise, the function is identical to pg_fetch_array, and almost as quick as pg_fetch_row (the difference is insignificant). See also pg_query, pg_fetch_array, pg_fetch_row and pg_fetch_result. Postgres fetch object

Failed connecting to postgres database

autor." ("; echo $data->jahr ."): "; echo $data->titel."
"; $row++; } ?>
$item[0]."\n";
    endwhile;
    $row++;
}
echo "----------\n"; 
?>
]]>
From 4.1.0, row became optional.
pg_fetch_result Returns values from a result resource Description mixedpg_fetch_result resourceresult introw_number mixedfield pg_fetch_result returns values from a result resource returned by pg_query. row_number is integer. field is field name(string) or field index (integer). The row_number and field specify what cell in the table of results to return. Row numbering starts from 0. Instead of naming the field, you may use the field index as an unquoted number. Field indices start from 0. PostgreSQL has many built in types and only the basic ones are directly supported here. All forms of integer, boolean and void types are returned as integer values. All forms of float, and real types are returned as float values. All other types, including arrays are returned as strings formatted in the same default PostgreSQL manner that you would see in the psql program. pg_fetch_row Get a row as an enumerated array Description arraypg_fetch_row resourceresult introw pg_fetch_row fetches one row of data from the result associated with the specified result resource. The row (record) is returned as an array. Each result column is stored in an array offset, starting at offset 0. It returns an array that corresponds to the fetched row, or &false; if there are no more rows. See also: pg_query, pg_fetch_array, pg_fetch_object and pg_fetch_result. Postgres fetch row "; } ?> ]]> From 4.1.0, row became optional. pg_field_is_null Test if a field is &null; Description intpg_field_is_null resourceresult introw mixedfield pg_field_is_null test if a field is &null; or not. It returns 1 if the field in the given row is &null;. It returns 0 if the field in the given row is NOT &null;. Field can be specified as column index (number) or fieldname (string). Row numbering starts at 0. This function used to be called pg_fieldisnull(). pg_field_name Returns the name of a field Description stringpg_field_name resourceresult intfield_number pg_field_name returns the name of the field occupying the given field_number in the given PostgreSQL result resource. Field numbering starts from 0. This function used to be called pg_fieldname(). See also pg_field_num. pg_field_num Returns the field number of the named field Description intpg_field_num resourceresult stringfield_name pg_field_num will return the number of the column (field) slot that corresponds to the field_name in the given PostgreSQL result resource. Field numbering starts at 0. This function will return -1 on error. This function used to be called pg_fieldnum(). See also pg_field_name. pg_field_prtlen Returns the printed length Description intpg_field_prtlen resourceresult introw_number stringfield_name pg_field_prtlen returns the actual printed length (number of characters) of a specific value in a PostgreSQL result. Row numbering starts at 0. This function will return -1 on an error. This function used to be called pg_field_prtlen(). See also pg_field_size. pg_field_size Returns the internal storage size of the named field Description intpg_field_size resourceresult intfield_number pg_field_size returns the internal storage size (in bytes) of the field number in the given PostgreSQL result. Field numbering starts at 0. A field size of -1 indicates a variable length field. This function will return &false; on error. This function used to be called pg_fieldsize(). See also pg_field_len and pg_field_type. pg_field_type Returns the type name for the corresponding field number Description stringpg_field_type resourceresult intfield_number pg_field_type returns a string containing the type name of the given field_number in the given PostgreSQL result resource. Field numbering starts at 0. This function used to be called pg_field_type(). See also pg_field_len and pg_field_name. pg_free_result Free result memory Description boolpg_free_result resourceresult pg_free_result only needs to be called if you are worried about using too much memory while your script is running. All result memory will automatically be freed when the script is finished. But, if you are sure you are not going to need the result data anymore in a script, you may call pg_free_result with the result resource as an argument and the associated result memory will be freed. It returns true on success and false if an error occurs. This function used to be called pg_field_len(). See also pg_query. pg_lo_close Close a large object Description boolpg_lo_close resourcelarge_object pg_lo_close closes a Large Object. large_object is a resource for the large object from pg_lo_open. To use the large object (lo) interface, it is necessary to enclose it within a transaction block. This function used to be called pg_loclose(). See also pg_lo_open, pg_lo_create and pg_lo_import. pg_lo_create Create a large object Description intpg_lo_create resourceconnection pg_lo_create creates a Large Object and returns the oid of the large object. connection specifies a valid database connection opened by pg_connect or pg_pconnect. PostgreSQL access modes INV_READ, INV_WRITE, and INV_ARCHIVE are not supported, the object is created always with both read and write access. INV_ARCHIVE has been removed from PostgreSQL itself (version 6.3 and above). It returns large object oid otherwise. It returns &false;, if an error occurred, To use the large object (lo) interface, it is necessary to enclose it within a transaction block. This function used to be called pg_locreate(). pg_lo_export Export a large object to file Description boolpg_lo_export intoid stringpathname resourceconnection The oid argument specifies oid of the large object to export and the pathname argument specifies the pathname of the file. It returns &false; if an error occurred, &true; otherwise. To use the large object (lo) interface, it is necessary to enclose it within a transaction block. This function used to be called pg_loexport(). See also pg_lo_import. pg_lo_import Import a large object from file Description intpg_lo_import stringpathname resourceconnection The pathname argument specifies the pathname of the file to be imported as a large object. It returns &false; if an error occurred, oid of the just created large object otherwise. To use the large object (lo) interface, it is necessary to enclose it within a transaction block. ¬e.sm.uidcheck; This function used to be called pg_loimport(). See also pg_lo_export and pg_lo_open. pg_lo_open Open a large object Description resourcepg_lo_open resourceconnection intoid stringmode pg_lo_open open a Large Object and returns large object resource. The resource encapsulates information about the connection. oid specifies a valid large object oid and mode can be either "r", "w", or "rw". It returns &false; if there is an error. Do not close the database connection before closing the large object resource. To use the large object (lo) interface, it is necessary to enclose it within a transaction block. This function used to be called pg_loopen(). See also pg_lo_close and pg_lo_create. pg_lo_read Read a large object Description stringpg_lo_read resourcelarge_object intlen pg_lo_read reads at most len bytes from a large object and returns it as a string. large_object specifies a valid large object resource andlen specifies the maximum allowable size of the large object segment. It returns &false; if there is an error. To use the large object (lo) interface, it is necessary to enclose it within a transaction block. This function used to be called pg_loread(). See also pg_lo_read_all. pg_lo_seek Seeks position of large object Description boolpg_lo_seek resourcelarge_object intoffset intwhence pg_lo_seek seeks position of large object resource. whence is PGSQL_SEEK_SET, PGSQL_SEEK_CUR or PGSQL_SEEK_END. See also pg_lo_tell. pg_lo_tell Returns current position of large object Description intpg_lo_tell resourcelarge_object pg_lo_tell returns current position (offset from the beginning of large object). See also pg_lo_seek. pg_lo_read_all Read a entire large object and send straight to browser Description intpg_lo_read_all resourcelarge_object pg_lo_read_all reads a large object and passes it straight through to the browser after sending all pending headers. Mainly intended for sending binary data like images or sound. It returns number of bytes read. It returns &false;, if an error occurred. To use the large object (lo) interface, it is necessary to enclose it within a transaction block. This function used to be called pg_loreadall(). See also pg_lo_read. pg_lo_unlink Delete a large object Description boolpg_lo_unlink resourceconnection intoid pg_lo_unlink deletes a large object with the oid. It returns &true; on success, otherwise returns &false;. To use the large object (lo) interface, it is necessary to enclose it within a transaction block. This function used to be called pg_lo_unlink(). See also pg_lo_create and pg_lo_import. pg_lo_write Write a large object Description intpg_lo_write resourcelarge_object stringdata pg_lo_write writes at most to a large object from a variable data and returns the number of bytes actually written, or &false; in the case of an error. large_object is a large object resource from pg_lo_open. To use the large object (lo) interface, it is necessary to enclose it within a transaction block. This function used to be called pg_lo_write(). See also pg_lo_create and pg_lo_open. pg_num_fields Returns the number of fields Description intpg_num_fields resourceresult pg_num_fields returns the number of fields (columns) in a PostgreSQL result. The argument is a result resource returned by pg_query. This function will return -1 on error. This function used to be called pg_numfields(). See also pg_num_rows and pg_affected_rows. pg_num_rows Returns the number of rows Description intpg_num_rows resourceresult pg_num_rows will return the number of rows in a PostgreSQL result resource. result is a query result resource returned by pg_query. This function will return -1 on error. Use pg_affected_rows to get number of rows affected by INSERT, UPDATE and DELETE query. This function used to be called pg_numrows(). See also pg_num_fields and pg_affected_rows. pg_host Returns the host name associated with the connection Description stringpg_host resourceconnection pg_host returns the host name of the given PostgreSQL connection resource is connected to. See also pg_connect and pg_pconnect. pg_port Return the port number associated with the connection Description intpg_port resourceconnection pg_port returns the port number that the given PostgreSQL connection resource is connected to. pg_dbname Get the database name Description stringpg_dbname resourceconnection pg_dbname returns the name of the database that the given PostgreSQL connection resource. It returns &false;, if connection is not a valid PostgreSQL connection resource. pg_options Get the options associated with the connection Description stringpg_options resourceconnection pg_options will return a string containing the options specified on the given PostgreSQL connection resource. pg_set_client_encoding Set the client encoding Description intpg_set_client_encoding resourceconnection stringencoding pg_set_client_encoding sets the client encoding and return 0 if success or -1 if error. encoding is the client encoding and can be either : SQL_ASCII, EUC_JP, EUC_CN, EUC_KR, EUC_TW, UNICODE, MULE_INTERNAL, LATINX (X=1...9), KOI8, WIN, ALT, SJIS, BIG5, WIN1250. Available encoding depends on your PostgreSQL and libpq version. Refer to PostgreSQL manual for supported encodings for your PostgreSQL. This function requires PHP-4.0.3 or higher and PostgreSQL-7.0 or higher. Supported encoding depends on PostgreSQL version. Refer to PostgreSQL manual for details. The function used to be called pg_setclientencoding. See also pg_client_encoding. pg_client_encoding Get the client encoding Description stringpg_client_encoding resourceconnection pg_client_encoding returns the client encoding as the string. The returned string should be either : SQL_ASCII, EUC_JP, EUC_CN, EUC_KR, EUC_TW, UNICODE, MULE_INTERNAL, LATINX (X=1...9), KOI8, WIN, ALT, SJIS, BIG5, WIN1250. This function requires PHP-4.0.3 or higher and PostgreSQL-7.0 or higher. If libpq is compiled without multibyte encoding support, pg_set_client_encoding always return "SQL_ASCII". Supported encoding depends on PostgreSQL version. Refer to PostgreSQL manual for details to enable multibyte support and encoding supported. The function used to be called pg_clientencoding. See also pg_set_client_encoding. pg_tty Return the tty name associated with the connection Description stringpg_tty resourceconnection pg_tty returns the tty name that server side debugging output is sent to on the given PostgreSQL connection resource. pg_trace Enable tracing a PostgreSQL connection Description boolpg_trace stringpathname stringmode resourceconnection pg_trace enables tracing of the PostgreSQL frontend/backend communication to a debugging file specified as pathname. To fully understand the results, one needs to be familiar with the internals of PostgreSQL communication protocol. For those who are not, it can still be useful for tracing errors in queries sent to the server, you could do for example grep '^To backend' trace.log and see what query actually were sent to the PostgreSQL server. For more information, refer to PostgreSQL manual. Filename and mode are the same as in fopen (mode defaults to 'w'), connection specifies the connection to trace and defaults to the last one opened. It returns &true; if pathname could be opened for logging, &false; otherwise. See also fopen and pg_untrace. pg_untrace Disable tracing of a PostgreSQL connection Description boolpg_untrace resourceconnection Stop tracing started by pg_trace. connection specifies the connection that was traced and defaults to the last one opened. Returns always &true;. See also pg_trace. pg_get_result Get asynchronous query result Description resourcepg_get_result resourceconnection pg_get_result get result resource from async query executed by pg_send_query. pg_send_query can send multiple queries to PostgreSQL server and pg_get_result is used to get query result one by one. It returns result resource. If there is no more results, it returns &false;. pg_result_error Get error message associated with result Description stringpg_result_error resourceresult pg_result_error returns error message associated with result resource. Therefore, user has better chance to get better error message than pg_last_error. See also pg_query, pg_send_query, pg_get_result, pg_last_error and pg_last_notice pg_result_status Get status of query result Description intpg_result_status resourceresult pg_result_status returns status of result resource. Possible retun values are PGSQL_EMPTY_QUERY, PGSQL_COMMAND_OK, PGSQL_TUPLES_OK, PGSQL_COPY_TO, PGSQL_COPY_FROM, PGSQL_BAD_RESPONSE, PGSQL_NONFATAL_ERROR and PGSQL_FATAL_ERROR. See also pg_connection_status. pg_send_query Send asynchronous query Description boolpg_send_query resourceconnection stringquery boolpg_send_query stringquery pg_send_query send asynchronous query to the connection. Unlike pg_query, it can send multiple query to PostgreSQL and get the result one by one using pg_get_result. Script execution is not block while query is executing. Use pg_connection_busy to check connection is busy (i.e. query is executing) Query may be canceled by calling pg_cancel_query. Although, user can send multiple query at once. User cannot send multiple query over busy connection. If query is sent while connection is busy, it waits until last query is finished and discards all result. See also pg_query, pg_cancel_query, pg_get_result and pg_connection_busy pg_cancel_query Cancel async query Description boolpg_cancel_query resourceconnection pg_cancel_query cancel asynchronous query sent by pg_send_query. You cannot cancel query executed by pg_query. See also pg_send_query, pg_cancel_result and pg_connection_busy pg_escape_bytea Escape binary for bytea type Description stringpg_escape_bytea stringdata pg_escape_string escapes string for bytea datatype. It returns escaped string. When you SELECT bytea type, PostgreSQL returns octal byte value prefixed by \. (e.g. \032) Users are supposed to convert back to binary formant by yourself. This function requires PostgreSQL 7.2 or later. With PostgreSQL 7.2.0 and 7.2.1, bytea type must be casted when you enable multi-byte support. i.e. INSERT INTO test_table (image) VALUES ('$image_escaped'::bytea); PostgreSQL 7.2.2 or later does not need cast. Exception is when client and backend character encoding does not match, there may be multi-byte stream error. User must cast to bytea to avoid this error. Newer PostgreSQL will support unescape function. Support for built-in unescape function will be added when it's available. See also pg_escape_string pg_escape_string Escape string for text/char type Description stringpg_escape_string stringdata pg_escape_string escapes string for text/char datatype. It returns escaped string for PostgreSQL. Use of this functon is recommended instead of addslashes. This function requires PostgreSQL 7.2 or later. See also pg_escape_bytea pg_metadata Get metadata for table. Description arraypg_metadata resourceconnection stringtable_name pg_metadata returns table definition for table_name as array. If there is error, it returns &false This function is experimental. See also pg_convert pg_convert Convert associative array value into suitable for SQL statement. Description arraypg_convert resourceconnection stringtable_name arrayassoc_array pg_convert check and convert assoc_array suitable for SQL statement. This function is experimental. See also pg_metadata pg_insert Insert array into table. Description boolpg_insert resourceconnection stringtable_name arrayassoc_array boolconvert pg_insert inserts assoc_array which has field=>value into table specified as table_name. If convert is not specified or &true, pg_convert applied to assoc_array. pg_insert ]]> This function is experimental. See also pg_convert pg_select Select records. Description arraypg_select resourceconnection stringtable_name arrayassoc_array boolconvert pg_select selects records specified by assoc_array which has field=>value. For successful query, it returns array contains all records and fields that match the condition specified by assoc_array. If convert is not specified or &true, pg_convert applied to assoc_array. pg_select ]]> This function is experimental. See also pg_convert pg_delete Delete records. Description longpg_delete resourceconnection stringtable_name arrayassoc_array boolconvert pg_delete deletes record condition specified by assoc_array which has field=>value. If convert is not specified or &true, pg_convert applied to assoc_array. pg_delete ]]> This function is experimental. See also pg_convert pg_update Update table. Description longpg_update resourceconnection stringtable_name arraycondition arraydata boolconvert pg_update updates records that matches condition with data If convert is not specified or &true, pg_convert applied to assoc_array. pg_update 'AA', 'field2'=>'BB'); // This is safe, since $_POST is converted automatically $res = pg_update($db, 'post_log', $_POST, $data); if ($res) { echo "Data is updated: $res\n"; } else { echo "User must have sent wrong inputs\n"; } ?> ]]> This function is experimental. See also pg_convert