From 5ab62289952662298865629052a8847808893a4d Mon Sep 17 00:00:00 2001 From: Egon Schmid Date: Mon, 27 Dec 1999 20:42:55 +0000 Subject: [PATCH] Hallo Catharina, jetzt sieht es etwas besser aus wie bei Hempels unterm Sofa. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@18013 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/pgsql.xml | 369 +++++++++++++++++++++++++------------------- 1 file changed, 212 insertions(+), 157 deletions(-) diff --git a/functions/pgsql.xml b/functions/pgsql.xml index 61e6e61070..66d3c38167 100644 --- a/functions/pgsql.xml +++ b/functions/pgsql.xml @@ -3,17 +3,18 @@ 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/SQL3 language support, transaction integrity, and type extensibility. PostgreSQL is a public-domain, open source - descendant of this original Berkeley code. + descendant of this original Berkeley code. + PostgreSQL is available without cost. The current version is - available at www.PostgreSQL.org. + 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 @@ -21,45 +22,51 @@ be enabled with the '-i' flag to postmaster and it's meaning is: "listen on TCP/IP sockets as well as Unix domain socket". - - - Postmaster and PHP - - - - Postmaster - PHP - Status - - - - - 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 - - - -
- + + Postmaster and PHP + + + + Postmaster + PHP + Status + + + + + 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"); + $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 @@ -83,10 +90,9 @@ pg_exec ($database, "begin"); pg_exec ($database, "commit") pg_exec ($database, "end") ?> - - - - + + +
@@ -103,11 +109,11 @@ pg_exec ($database, "end") Returns false if connection is not a valid connection index, true otherwise. Closes down the connection to a PostgreSQL database - associated with the given connection index. + associated with the given connection index. + - pg_cmdTuples @@ -120,21 +126,20 @@ pg_exec ($database, "end") int result_id - pg_cmdTuples() returns the number of tuples (instances) affected - by INSERT, UPDATE, and DELETE queries. If no tuple is affected the - function will return 0. - - - pg_cmdtuples - + pg_cmdTuples returns the number of tuples + (instances) affected by INSERT, UPDATE, and DELETE queries. If no + tuple is affected the function will return 0. + + pg_cmdtuples + <?php $result = pg_exec($conn, "INSERT INTO verlag VALUES ('Autor')"); $cmdtuples = pg_cmdtuples($result); echo $cmdtuples . " <- cmdtuples affected."; ?> - - - + + + @@ -160,16 +165,19 @@ echo $cmdtuples . " <- cmdtuples affected."; including the port number. The options and tty arguments are optional and can be left out. This function returns a connection index that is needed by other PostgreSQL functions. You can have - multiple connections open at once. + multiple connections open at once. + A connection can also established with the following command: $conn = pg_connect("dbname=marliese port=5432"); Other parameters besides dbname and port are host, tty, options, - user and password. + user and password. + - See also pg_pConnect. + See also pg_pConnect. + @@ -187,7 +195,8 @@ echo $cmdtuples . " <- cmdtuples affected."; Returns the name of the database that the given PostgreSQL connection index is connected to, or false if connection is not a - valid connection index. + valid connection index. + @@ -205,10 +214,11 @@ echo $cmdtuples . " <- cmdtuples affected."; Returns a string containing the error message, false on failure. Details about the error probably cannot be retrieved using the - pg_errormessage() function if an error occured + pg_errormessage function if an error occured on the last database action for which a valid connection exists, this function will return a string containing the error message - generated by the backend server. + generated by the backend server. + @@ -234,12 +244,15 @@ echo $cmdtuples . " <- cmdtuples affected."; index that was returned by pg_Connect. The return value of this function is an index to be used to access the results from other PostgreSQL functions. - - PHP/FI returned 1 if the query was not expected to return data - (inserts or updates, for example) and greater than 1 even on - selects that did not return anything. No such assumption can be - made in PHP. - + + + PHP/FI returned 1 if the query was not expected to return data + (inserts or updates, for example) and greater than 1 even on + selects that did not return anything. No such assumption can be + made in PHP. + + + @@ -265,20 +278,24 @@ echo $cmdtuples . " <- cmdtuples affected."; pg_fetch_array is an extended version of pg_fetch_row. In addition to storing the data in the numeric indices of the result array, it also stores - the data in associative indices, using the field names as keys. + the data in associative indices, using the field names as keys. + The third optional argument result_type in pg_fetch_array is a constant and can take the following values: PGSQL_ASSOC, PGSQL_NUM, and PGSQL_BOTH. - Result_type was added in PHP 4.0. - + Result_type was added in PHP 4.0. + + + An important thing to note is that using pg_fetch_array is NOT significantly slower than using pg_fetch_row, while it - provides a significant added value. + provides a significant added value. + For further details, also see pg_fetch_row @@ -305,9 +322,8 @@ echo $arr[0] . " <- array\n"; $arr = pg_fetch_array ($result, 1); echo $arr["author"] . " <- array\n"; ?> - + - @@ -328,32 +344,37 @@ echo $arr["author"] . " <- array\n"; Returns: An object with properties that correspond to the fetched - row, or false if there are no more rows. + row, or false if there are no more rows. + 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). + their offsets (numbers are illegal property names). + The third optional argument result_type in pg_fetch_object is a constant and can take the following values: PGSQL_ASSOC, PGSQL_NUM, and PGSQL_BOTH. - Result_type was added in PHP 4.0. - + 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_fetch_array and - pg_fetch_row. - - - Postgres fetch object - + insignificant). + + + See also: pg_fetch_array and + pg_fetch_row. + + Postgres fetch object + <?php $database = "verlag"; $db_conn = pg_connect ("localhost", "5432", "", "", $database); @@ -391,9 +412,9 @@ echo "----------\n"; ?> pg_freeResult ($qu); pg_close ($db_conn); ?> - - - + + + @@ -411,24 +432,26 @@ pg_close ($db_conn); Returns: An array that corresponds to the fetched row, or false - if there are no more rows. + if there are no more rows. + pg_fetch_row fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an - array offset, starting at offset 0. + array offset, starting at offset 0. + Subsequent call to pg_fetch_row would return the next row in the result set, or false if there are no - more rows. + more rows. + See also: pg_fetch_array, - pg_fetch_object, - pg_result. - - - Postgres fetch row - + pg_fetch_object, + pg_result. + + Postgres fetch row + <?php $conn = pg_pconnect("","","","","publisher"); if (!$conn) { @@ -451,9 +474,9 @@ echo $row[0] . " <- row\n"; $row = pg_fetch_row ($result, 2); echo $row[1] . " <- row\n"; ?> - - - + + + @@ -474,7 +497,8 @@ echo $row[1] . " <- row\n"; Test if a field is NULL or not. Returns 0 if the field in the given row is not NULL. Returns 1 if the field in the given row is NULL. Field can be specified as number or fieldname. Row - numbering starts at 0. + numbering starts at 0. + @@ -491,9 +515,10 @@ echo $row[1] . " <- row\n"; int field_number - pg_FieldName() will return the name of the field occupying the - given column number in the given PostgreSQL result identifier. - Field numbering starts from 0. + pg_FieldName will return the name of the + field occupying the given column number in the given PostgreSQL + result identifier. Field numbering starts from 0. + @@ -510,10 +535,11 @@ echo $row[1] . " <- row\n"; string field_name - pg_FieldNum() will return the number of the column slot that - corresponds to the named field in the given PosgreSQL result - identifier. Field numbering starts at 0. This function will - return -1 on error. + pg_FieldNum will return the number of the + column slot that corresponds to the named field in the given + PosgreSQL result identifier. Field numbering starts at 0. This + function will return -1 on error. + @@ -531,16 +557,20 @@ echo $row[1] . " <- row\n"; string field_name - pg_FieldPrtLen() will return 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. + pg_FieldPrtLen will return 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. + - pg_FieldSize Returns the internal - storage size of the named field + pg_FieldSize + + Returns the internal storage size of the named field + Description @@ -554,14 +584,16 @@ echo $row[1] . " <- row\n"; 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. + false on error. + pg_FieldType - Returns the type name for the corresponding field number + + Returns the type name for the corresponding field number @@ -572,9 +604,10 @@ echo $row[1] . " <- row\n"; int field_number - pg_FieldType() will return a string containing the type name of - the given field in the given PostgreSQL result identifier. Field - numbering starts at 0. + pg_FieldType will return a string containing + the type name of the given field in the given PostgreSQL result + identifier. Field numbering starts at 0. + @@ -596,7 +629,8 @@ echo $row[1] . " <- row\n"; 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 identifier as - an argument and the associated result memory will be freed. + an argument and the associated result memory will be freed. + @@ -618,7 +652,8 @@ echo $row[1] . " <- row\n"; and was an SQL INSERT. This function will return a positive integer if there was a valid Oid. It will return -1 if an error occured or the last command sent via pg_Exec - was not an INSERT. + was not an INSERT. + @@ -634,8 +669,9 @@ echo $row[1] . " <- row\n"; int connection_id - pg_Host() will return the host name of the given PostgreSQL - connection identifier is connected to. + pg_Host will return the host name of the + given PostgreSQL connection identifier is connected to. + @@ -652,8 +688,9 @@ echo $row[1] . " <- row\n"; pg_loclose closes an Inversion Large - Object. fd is a file descriptor for the large - object from pg_loopen. + Object. fd is a file descriptor for the + large object from pg_loopen. + @@ -671,11 +708,12 @@ echo $row[1] . " <- row\n"; pg_locreate creates an Inversion Large Object and returns the oid of the large object. - conn specifies a valid database connection. - 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). + conn specifies a valid database + connection. 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). + @@ -698,7 +736,8 @@ echo $row[1] . " <- row\n"; encapsulates information about the connection. Do not close the connection before closing the large object file descriptor. objoid specifies a valid large object oid - and mode can be either "r", "w", or "rw". + and mode can be either "r", "w", or "rw". + @@ -720,11 +759,12 @@ echo $row[1] . " <- row\n"; returns it as a string. fd specifies a valid large object file descriptor andlen specifies the maximum - allowable size of the large object segment. + allowable size of the large object segment. + - + pg_loreadall read a entire large object @@ -738,11 +778,12 @@ echo $row[1] . " <- row\n"; 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. + headers. Mainly intended for sending binary data like images or sound. + - + pg_lounlink delete a large object @@ -756,11 +797,12 @@ echo $row[1] . " <- row\n"; pg_lounlink deletes a large object with the - lobjid identifier for that large object. + lobjid identifier for that large object. + - + pg_lowrite write a large object @@ -777,7 +819,8 @@ echo $row[1] . " <- row\n"; from a variable buf and returns the number of bytes actually written, or false in the case of an error. fd is a file descriptor for the large - object from pg_loopen. + object from pg_loopen. + @@ -793,10 +836,11 @@ echo $row[1] . " <- row\n"; int result_id - pg_NumFields() will return the number of fields (columns) in a - PostgreSQL result. The argument is a valid result identifier - returned by pg_Exec. This function will - return -1 on error. + pg_NumFields will return the number of + fields (columns) in a PostgreSQL result. The argument is a valid + result identifier returned by pg_Exec. This + function will return -1 on error. + @@ -815,7 +859,8 @@ echo $row[1] . " <- row\n"; pg_NumRows will return the number of rows in a PostgreSQL result. The argument is a valid result identifier returned by pg_Exec. This function will - return -1 on error. + return -1 on error. + @@ -831,15 +876,19 @@ echo $row[1] . " <- row\n"; int connection_id - pg_Options() will return a string containing the options - specified on the given PostgreSQL connection identifier. + pg_Options will return a string containing + the options specified on the given PostgreSQL connection + identifier. + pg_pConnect - make a persistent database connection + + Make a persistent database connection + Description @@ -859,15 +908,16 @@ echo $row[1] . " <- row\n"; optional and can be left out. This function returns a connection index that is needed by other PostgreSQL functions. You can have multiple persistent connections open at once. See also - pg_Connect. + pg_Connect. + A connection can also established with the following command: $conn = pg_pconnect("dbname=marliese port=5432"); Other parameters besides dbname and port are host, tty, options, - user and password. - + user and password. + @@ -883,8 +933,9 @@ echo $row[1] . " <- row\n"; int connection_id - pg_Port() will return the port number that the given PostgreSQL - connection identifier is connected to. + pg_Port will return the port number that the + given PostgreSQL connection identifier is connected to. + @@ -902,13 +953,14 @@ echo $row[1] . " <- row\n"; mixed fieldname - pg_Result() will return values from a result identifier produced - by pg_Exec. The + pg_Result will return values from a result + identifier produced by pg_Exec. The row_number and fieldname 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. + 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 oid @@ -916,7 +968,8 @@ echo $row[1] . " <- row\n"; real types are returned as double 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. + psql program. + @@ -932,8 +985,10 @@ echo $row[1] . " <- row\n"; int connection_id - pg_tty() will return the tty name that server side debugging - output is sent to on the given PostgreSQL connection identifier. + pg_tty will return the tty name that server + side debugging output is sent to on the given PostgreSQL + connection identifier. + @@ -949,7 +1004,7 @@ sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil -sgml-default-dtd-file:"../manual.ced" +sgml-default-dtd-file:"../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil