PostgreSQL functions PostgreSQL Use of PostgreSQL module with PHP 4.0.6 is not recommended due to a bug in notice message handling. PostgreSQL function names will be changed in 4.2.0 release to confirm current coding standard. Most of new names will have additional under score(s), e.g. pg_lo_open(). Some functions are renamed to different name for consistency. e.g. pg_exec() to pg_query(). Older names may be used in 4.2.0 and a few releases from 4.2.0, but they may be deleted in the future. CVS version has new function names. Obsolete pg_connect()/pg_pconnect() may be depreciated to support async connect feature in the future. 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 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 charactor encoding including multibyte character encoding. The current version and more information about PostgreSQL is available at www.postgresql.org. In order to enable PostgreSQL support, "--enable-pgsql[=DIR]" 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 file which comes with source distribution. Not all functions are supported by all builds. It depends on your libpq (The PostgreSQL C Client interface) versoin 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 openned 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 variable affects PostgreSQL server/client behavior. For example, PostgreSQL module will lookup PGHOST environment variable when hostname is omitted in connection string. Supported environment variables are different from version to version. Refer to PostgreSQL Programmer's Manual (libpq - Environment Variables) for details. From PostgreSQL 7.1.0, text data type has 1GB as its max size. Older PostgreSQL's text data type is limitted by block size. (Default 8KB. Max 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 ]]> Do not close connection resource before closing large object resource.
pg_close Close a PostgreSQL connection Description bool pg_close resource connection pg_close closes down the non-persistent connection to a PostgreSQL database associated with the given connection resource. It returns &true;, if connection is a valid connection resource, otherwise it return &false;. pg_close is not usually necessary, as non-persistent open links are automatically closed at the end of the script's execution. pg_close will not close persistent links generated by pg_pconnect. If there is open large object resource on the connection, do not close the connection before closing all large object resources. pg_cmdtuples Returns number of affected records(tuples) Description int pg_cmdtuples resource result pg_cmdtuples returns the number of tuples (instances/records/rows) affected by INSERT, UPDATE, and DELETE queries executed by pg_exec. If no tuple is affected by this function, it will return 0. <function>pg_cmdtuples</function> ]]> See also pg_exec and pg_numrows. pg_connect Open a PostgreSQL connection Description resource pg_connect string connection_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 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 arguments, 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 patameters. (i.e. Use different username) Syntax supports 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_dbname Get the database name Description string pg_dbname resource connection pg_dbname returns the name of the database that the given PostgreSQL connection resource. It retuns &false;, if connection is not a valid PostgreSQL connection resource. pg_end_copy Sync with PostgreSQL backend Description bool pg_end_copy resource connection pg_end_copy syncs 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" error with the frontend. It returns &true; for success, otherwise it returns &false;. For further details and an example, see also pg_put_line. pg_errormessage Get the last error message string of a connection Description string pg_errormessage resource connection pg_errormessage returns a string containing the last error message for given connection. It returns &false; on failure. pg_errormessage returns the last error message for given connection and error message may be overwritten if other libpq functions are called on the connection. PostgreSQL functions calls libpq functions internally. Therefore, details about the error may not be retrieved using the pg_errormessage function. pg_result_error_message() will be added from 4.2.0 to get last error for the result resource. pg_exec Execute a query Description resource pg_exec resource connection string query pg_exec 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_errormessage function if connection is valid. pg_errormessage 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_exec. If connection is not used, 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. See also pg_connect, pg_pconnect, pg_fetch_array, pg_fetch_object, pg_numrows, and pg_cmdtuples. pg_fetch_array Fetch a row as an array Description array pg_fetch_array resource result int row int result_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 retrived. First row is 0. result_type is optional parameter controls how return value is initilized. 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_result. PostgreSQL fetch array ]]> pg_fetch_object Fetch a row as an object Description object pg_fetch_object resource result int row int result_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 initilized. 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_exec, pg_fetch_array, pg_fetch_row and pg_result. Postgres fetch object

Failed connecting to postgres database

autor." ("; echo $data->jahr ."): "; echo $data->titel."
"; $row++; } ?>
$item[0]."\n";
    endwhile;
    $row++;
}
echo "----------\n"; 
?>
]]>
pg_fetch_row Get a row as an enumerated array Description array pg_fetch_row resource result int row 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_exec, pg_fetch_array, pg_fetch_object and pg_result. Postgres fetch row "; } ?> ]]> pg_fieldisnull Test if a field is &null; Description int pg_fieldisnull resource result int row mixed field pg_fieldisnull 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 colum index (number) or fieldname (string). Row numbering starts at 0. pg_fieldname Returns the name of a field Description string pg_fieldname resource result int field_number pg_fieldname returns the name of the field occupying the given field_number in the given PostgreSQL result resource. Field numbering starts from 0. See also pg_filednum. pg_fieldnum Returns the field number of the named field Description int pg_fieldnum resource result string field_name pg_fieldnum will return the number of the column (field) slot that corresponds to the field_name in the given PosgreSQL result resource. Field numbering starts at 0. This function will return -1 on error. See also pg_fieldname. pg_fieldprtlen Returns the printed length Description int pg_fieldprtlen resource result int row_number string field_name pg_fieldprtlen 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. See also pg_fieldsize. pg_fieldsize Returns the internal storage size of the named field Description int pg_fieldsize resource result int field_number pg_fieldsize 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. See also pg_fieldlen and pg_fieldtype. pg_fieldtype Returns the type name for the corresponding field number Description string pg_fieldtype resource result int field_number pg_fieldtype returns a string containing the type name of the given field_number in the given PostgreSQL result resource. Field numbering starts at 0. See also pg_fieldlen and pg_fieldname. pg_freeresult Free result memory Description bool pg_freeresult resource result pg_freeresult 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_freeresult 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. See also pg_exec. pg_getlastoid Returns the last object's oid Description int pg_getlastoid resource result pg_getlastoid 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_exec 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_exec was not an INSERT or INSERT is failed. See also pg_exec. pg_host Returns the host name associated with the connection Description string pg_host resource connection pg_host returns the host name of the given PostgreSQL connection resource is connected to. See also pg_connect and pg_pconnect. pg_last_notice Returns the last notice message from PostgreSQL server Description string pg_last_notice resource connection pg_last_notice returns the last notice message from PostgreSQL server specified by connection. PostgreSQL server set notice message when transaction cannot be continued. There one can avoid issuing useless SQL using pg_exec using pg_last_notice. There are other cases that PostgreSQL server sets notice message. Programmer must check contents of notice message if it is related to transaction or not. This function is EXPERIMENTAL and it is not fully implemented yet. pg_last_notice is added form PHP 4.0.6. However, PHP 4.0.6 has problem with notice message handling. Use of PostgreSQL module with PHP 4.0.6 is not recommended even if you are not using pg_last_notice. See also pg_exec and pg_errormessage. pg_loclose Close a large object Description bool pg_loclose resource large_object pg_loclose closes an Inversion Large Object. large_object is a resource for the large object from pg_loopen. To use the large object (lo) interface, it is necessary to enclose it within a transaction block. See also pg_loopen, pg_locreate and pg_loimport. pg_locreate Create a large object Description int pg_locreate resource connection pg_locreate creates an Inversion 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 retuns &false;, if an error occurred, To use the large object (lo) interface, it is necessary to enclose it within a transaction block. pg_loexport Export a large object to file Description bool pg_loexport int oid string pathname resource connection 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. See also pg_loimport. pg_loimport Import a large object from file Description int pg_loimport string pathname resource connection 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; See also pg_loexport and pg_loopen. pg_loopen Open a large object Description resource pg_loopen resource connection int oid string mode pg_loopen open an Inversion 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. See also pg_loclose and pg_locreate. pg_loread Read a large object Description string pg_loread resource large_object int len pg_loread 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. See also pg_loreadall. pg_loreadall Read a entire large object and send straight to browser Description int pg_loreadall resource large_object pg_loreadall 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 occured. To use the large object (lo) interface, it is necessary to enclose it within a transaction block. See also pg_loread. pg_lounlink Delete a large object Description bool pg_lounlink resource connection int oid pg_lounlink deletes a large object with the oid. It rreturn &true; on success, otherwise returns &false;. To use the large object (lo) interface, it is necessary to enclose it within a transaction block. See also pg_locreate and pg_loimport. pg_lowrite Write a large object Description int pg_lowrite resource large_object string data pg_lowrite 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_loopen. To use the large object (lo) interface, it is necessary to enclose it within a transaction block. See also pg_locreate and pg_loopen. pg_numfields Returns the number of fields Description int pg_numfields resource result pg_numfields returns the number of fields (columns) in a PostgreSQL result. The argument is a result resource returned by pg_exec. This function will return -1 on error. See also pg_numrows and pg_cmdtuples. pg_numrows Returns the number of rows Description int pg_numrows resource result pg_numrows will return the number of rows in a PostgreSQL result resource. result is a qeury result resource returned by pg_exec. This function will return -1 on error. Use pg_cmdtuples to get number of rows affected by INSERT, UPDATE and DELETE query. See also pg_numfields and pg_cmdtuples. pg_options Get the options associated with the connection Description string pg_options resource connection pg_options will return a string containing the options specified on the given PostgreSQL connection resource. pg_pconnect Open a persistent PostgreSQL connection Description int pg_pconnect string connection_string pg_pconnect opens a connection to a PostgreSQL database. It returns a connection resource that is needed by other PostgreSQL functions. It returns a connection resource on success, or &false; if the connection could not be made. The arguments should be within a quoted string. The arguments available include host, port, tty, options, dbname, user, and password. Using pg_connect ]]> If a second call is made to pg_pconnect with the same arguments, 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 patameters. (i.e. Use different username) Multiple parameters syntax for pg_pconnect $conn = pg_pconnect ("host", "port", "options", "tty", "dbname") has been deprecated. To enable persistent connection, pgsql.allow_persistent php.ini directive must be set to "On". (Default is On) Max number of persistent connection can be defined by pgsql.max_persistent php.ini directive. (Default is -1 which is no limit) Total number of connection can be set by pgsql.max_links php.ini directive. pg_close will not close persistent links generated by pg_pconnect. See also pg_connect. pg_port Return the port number associated with the connection Description int pg_port resource connection pg_port returns the port number that the given PostgreSQL connection resource is connected to. pg_put_line Send a NULL-terminated string to PostgreSQL backend Description bool pg_put_line resource connection string data 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. It returns &true; if successfull, &false; otherwise. Note the application must explicitly send the two characters "\." on a final 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_result Returns values from a result resource Description mixed pg_result resource result int row_number mixed field pg_result returns values from a result resource returned by pg_exec. row_number is integer. field is field name(string) or field index (integer). The row_number and field sepcify 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_set_client_encoding Set the client encoding Description int pg_set_client_encoding resource connection string encoding 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. This function requires PHP-4.0.3 or higher and PostgreSQL-7.0 or higher. Supported encoding depends on PostgreSQL version. Refer to PostgreSQL manaul for details. The function used to be called pg_setclientencoding. See also pg_client_encoding. pg_client_encoding Get the client encoding Description string pg_client_encoding resource connection 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 manaul for details to enable multibyte support and encoding supported. The function used to be called pg_clientencoding. See also pg_set_client_encoding. pg_trace Enable tracing a PostgreSQL connection Description bool pg_trace string pathname string mode resource connection 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_tty Return the tty name associated with the connection Description string pg_tty resource connection pg_tty returns the tty name that server side debugging output is sent to on the given PostgreSQL connection resource. pg_untrace Disable tracing of a PostgreSQL connection Description bool pg_untrace resource connection 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 resource pg_get_result resource connection &warn.undocumented.func; pg_request_cancel Cancel request Description bool pg_request_cancel resource connection &warn.undocumented.func; pg_is_busy Get connection is busy or not Description bool pg_is_busy resource connection &warn.undocumented.func; pg_send_query Send asynchronous query Description bool pg_send_query resource connection string qeury bool pg_send_query string qeury &warn.undocumented.func; pg_cancel_query Cancel request Description bool pg_cancel_query resource connection &warn.undocumented.func; pg_connection_busy Get connection is busy or not Description bool pg_connection_busy resource connection &warn.undocumented.func; pg_connection_reset Reset connection (reconnect) Description bool pg_connection_reset resource connection &warn.undocumented.func; pg_connection_status Get connection status Description int pg_connection_status resource connnection &warn.undocumented.func; pg_copy_from No description given yet Description int pg_copy_from int connection string table_name array rows string delimiter string null_as &warn.undocumented.func; pg_copy_to Send null-terminated string to backend server Description int pg_copy_to int connection string table_name string delimiter string null_as &warn.undocumented.func; pg_escape_bytea Escape binary for bytea type Description string pg_escape_bytea string data &warn.undocumented.func; pg_escape_string Escape string for text/char type Description string pg_escape_string string data &warn.undocumented.func; pg_lo_close Close a large object Description bool pg_lo_close resource large_object &warn.undocumented.func; pg_lo_seek Seeks position of large object Description bool pg_lo_seek resource large_object int offset int whence &warn.undocumented.func; pg_lo_tell Returns current position of large object Description int pg_lo_tell resource large_object &warn.undocumented.func; pg_result_error Get error message associated with result Description string pg_result_error resource result &warn.undocumented.func; pg_result_status Get status of query result Description int pg_result_status resource result &warn.undocumented.func;