电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> PHP>>PHP 3 专题 -- 函数英文列表五:

PHP 3 专题 -- 函数英文列表五

来源:www.cncfan.com | 2006-1-11 | (有2448人读过)

Description
int sybase_select_db(string database_name, int link_identifier);

Returns: true on success, false on error

sybase_select_db() sets the current active database on the server that's associated with the specified link identifier. If no link identifier is specified, the last opened link is assumed. If no link is open, the function will try to establish a link as if sybase_connect() was called, and use it.

Every subsequent call to sybase_query() will be made on the active database.

See also: sybase_connect(), sybase_pconnect(), and sybase_query()

XXVIII. Network Functions
Table of Contents
fsockopen
set_socket_blocking
gethostbyaddr
gethostbyname
gethostbynamel
checkdnsrr
getmxrr
openlog
syslog
closelog
debugger_on
debugger_off
fsockopen
fsockopen -- Open Internet or Unix domain socket connection.

Description
int fsockopen(string hostname, int port, int [errno], string [errstr]);

Opens an Internet domain socket connection to hostname on port port and returns a file pointer, which may be used by fgets(), fgetss(), fputs(), and fclose(). If the call fails, it will return FALSE and if the optional errno and errstr arguments are present they will be set to indicate the actual system level error that ocurred on the system-level connect() call. If the returned errno is 0, but the function returned FALSE, it is an indication that the error occurred before the connect() call. This is most likely due to a problem initializing the socket. Note that the errno and errstr arguments should be passed by reference.

If port is 0 and the operating system supports Unix domain sockets, hostname will be used as the filename of a Unix domain socket to connect to.

The socket will by default be opened in blocking mode. You can switch it to non-blocking mode by using the set_socket_blocking().

Example 1. fsockopen example

$fp = fsockopen("www.php.net", 80, &$errno, &$errstr);
if(!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs($fp,"GET / HTTP/1.0\n\n");
while(!feof($fp)) {
echo fgets($fp,128);
}
fclose($fp);
}



set_socket_blocking
set_socket_blocking -- Set blocking/non-blocking mode on a socket

Description
int set_socket_blocking(int socket descriptor, int mode);

If mode is false, the given socket descriptor will be switched to non-blocking mode, and if true, it will be switched to blocking mode. This affects calls like fgets() that read from the socket. In non-blocking mode an fgets() call will always return right away while in blocking mode it will wait for data to become available on the socket.

gethostbyaddr
gethostbyaddr -- Get the Internet host name corresponding to a given IP address.

Description
string gethostbyaddr(string ip_address);

Returns the host name of the Internet host specified by ip_address. If an error occurs, returns ip_address.

See also gethostbyname().

gethostbyname
gethostbyname -- Get the IP address corresponding to a given Internet host name.

Description
string gethostbyname(string hostname);

Returns the IP address of the Internet host specified by hostname.

See also gethostbyaddr().

gethostbynamel
gethostbynamel -- Get a list of IP addresses corresponding to a given Internet host name.

Description
array gethostbynamel(string hostname);

Returns a list of IP addresses to which the Internet host specified by hostname resolves.

See also gethostbyname(), gethostbyaddr(), checkdnsrr(), getmxrr(), and the named(8) manual page.

checkdnsrr
checkdnsrr -- Check DNS records corresponding to a given Internet host name or IP address.

Description
int checkdnsrr(string host, string [type]);

Searches DNS for records of type type corresponding to host. Returns true if any records are found; returns false if no records were found or if an error occurred.

type may be any one of: A, MX, NS, SOA, PTR, CNAME, or ANY. The default is MX.

host may either be the IP address in dotted-quad notation or the host name.

See also getmxrr(), gethostbyaddr(), gethostbyname(), gethostbynamel(), and the named(8) manual page.

getmxrr
getmxrr -- Get MX records corresponding to a given Internet host name.

Description
int getmxrr(string hostname, array mxhosts, array [weight]);

Searches DNS for MX records corresponding to hostname. Returns true if any records are found; returns false if no records were found or if an error occurred.

A list of the MX records found is placed into the array mxhosts. If the weight array is given, it will be filled with the weight information gathered.

See also checkdnsrr(), gethostbyname(), gethostbynamel(), gethostbyaddr(), and the named(8) manual page.

openlog
openlog -- open connection to system logger

Description
int openlog(string ident, int option, int facility);

openlog() opens a connection to the system logger for a program. The string ident is added to each message. Values for option and facility are given in the next section. The use of openlog() is optional; It will automatically be called by syslog() if necessary, in which case ident will default to false. See also syslog() and closelog().

syslog
syslog -- generate a system log message

Description
int syslog(int priority, string message);

syslog() generates a log message that will be distributed by the system logger. priority is a combination of the facility and the level, values for which are given in the next section. The remaining argument is the message to send, except that the two characters %m will be replaced by the error message string (strerror) corresponding to the present value of errno.

More information on the syslog facilities can be found in the man pages for syslog on Unix machines.

On Windows NT, the syslog service is emulated using the Event Log.

closelog
closelog -- close connection to system logger

Description
int closelog(void);

closelog() closes the descriptor being used to write to the system logger. The use of closelog() is optional.

debugger_on
debugger_on -- enable internal PHP debugger

Description
int debugger_on(string address);

Enables the internal PHP debugger, connecting it to address. The debugger is still under development.

debugger_off
debugger_off -- disable internal PHP debugger

Description
int debugger_off(void);

Disables the internal PHP debugger. The debugger is still under development.

XXIX. ODBC Functions
Table of Contents
odbc_autocommit
odbc_binmode
odbc_close
odbc_close_all
odbc_commit
odbc_connect
odbc_cursor
odbc_do
odbc_exec
odbc_execute
odbc_fetch_into
odbc_fetch_row
odbc_field_name
odbc_field_type
odbc_field_len
odbc_free_result
odbc_longreadlen
odbc_num_fields
odbc_pconnect
odbc_prepare
odbc_num_rows
odbc_result
odbc_result_all
odbc_rollback
odbc_autocommit
odbc_autocommit -- Toggle autocommit behaviour

Description
int odbc_autocommit(int connection_id, int [OnOff]);

Without the OnOff parameter, this function returns auto-commit status for connection_id. True is returned if auto-commit is on, false if it is off or an error occurs.

If OnOff is true, auto-commit is enabled, if it is false auto-commit is disabled. Returns true on success, false on failure.

By default, auto-commit is on for a connection. Disabling auto-commit is equivalent with starting a transaction.

See also odbc_commit() and odbc_rollback().

odbc_binmode
odbc_binmode -- handling of binary column data

Description
int odbc_binmode(int result_id, int mode);

(ODBC SQL types affected: BINARY, VARBINARY, LONGVARBINARY)

ODBC_BINMODE_PASSTHRU: Passthru BINARY data

ODBC_BINMODE_RETURN: Return as is

ODBC_BINMODE_CONVERT: Convert to char and return

When binary SQL data is converted to character C data, each byte (8 bits) of source data is represented as two ASCII characters. These characters are the ASCII character representation of the number in its hexadecimal form. For example, a binary 00000001 is converted to "01" and a binary 11111111 is converted to "FF".

Table 1. LONGVARBINARY handling


binmode longreadlen result
ODBC_BINMODE_PASSTHRU 0 passthru
ODBC_BINMODE_RETURN 0 passthru
ODBC_BINMODE_CONVERT 0 passthru
ODBC_BINMODE_PASSTHRU 0 passthru
ODBC_BINMODE_PASSTHRU >0 passthru
ODBC_BINMODE_RETURN >0 return as is
ODBC_BINMODE_CONVERT >0 return as char

If odbc_fetch_into() is used, passthru means that an empty string is returned for these columns.

If result_id is 0, the settings apply as default for new results.

Note: Default for longreadlen is 4096 and binmode defaults to ODBC_BINMODE_RETURN. Handling of binary long columns is also affected by odbc_longreadlen()

odbc_close
odbc_close -- Close an ODBC connection

Description
void odbc_close(int connection_id);

odbc_close() will close down the connection to the database server associated with the given connection identifier.

Note: This function will fail if there are open transactions on this connection. The connection will remain open in this case.

odbc_close_all
odbc_close_all -- Close all ODBC connections

Description
void odbc_close_all(void);

odbc_close_all() will close down all connections to database server(s).

Note: This function will fail if there are open transactions on a connection. This connection will remain open in this case.

odbc_commit
odbc_commit -- Commit an ODBC transaction

Description
int odbc_commit(int connection_id);

Returns: true on success, false on failure. All pending transactions on connection_id are committed.

odbc_connect
odbc_connect -- Connect to a datasource

Description
int odbc_connect(string dsn, string user, string password);

Returns an ODBC connection id or 0 (false) on error.

The connection id returned by this functions is needed by other ODBC functions. You can have multiple connections open at once. For persistent connections see odbc_pconnect().

odbc_cursor
odbc_cursor -- Get cursorname

Description
string odbc_cursor(int result_id);

odbc_cursor will return a cursorname for the given result_id.

odbc_do
odbc_do -- synonym for odbc_exec()

Description
string odbc_do(int conn_id, string query);

odbc_do will execute a query on the given connection

odbc_exec
odbc_exec -- Prepare and execute a SQL statement

Description
int odbc_exec(int connection_id, string query_string);

Returns false on error. Returns an ODBC result identifier if the SQL command was executed successfully.

odbc_exec() will send an SQL statement to the database server specified by connection_id. This parameter must be a valid identifier returned by odbc_connect() or odbc_pconnect().

See also: odbc_prepare() and odbc_execute() for multiple execution of SQL statements.

odbc_execute
odbc_execute -- execute a prepared statement

Description
int odbc_execute(int result_id, array [parameters_array]);

Executes a statement prepared with odbc_prepare(). Returns true on successful execution, false otherwise. The array arameters_array only needs to be given if you really have parameters in your statement.

odbc_fetch_into
odbc_fetch_into -- Fetch one result row into array

Description
int odbc_fetch_into(int result_id, int [rownumber], array result_array);

Returns the number of columns in the result; false on error. result_array must be passed by reference, but it can be of any type since it will be converted to type array. The array will contain the column values starting at array index 0.

odbc_fetch_row
odbc_fetch_row -- Fetch a row

Description
int odbc_fetch_row(int result_id, int [row_number]);

If odbc_fetch_row() was succesful (there was a row), true is returned. If there are no more rows, false is returned.

odbc_fetch_row() fetches a row of the data that was returned by odbc_do() / odbc_exec(). After odbc_fetch_row() is called, the fields of that row can be accessed with odbc_result().

If row_number is not specified, odbc_fetch_row() will try to fetch the next row in the result set. Calls to odbc_fetch_row() with and without row_number can be mixed.

To step through the result more than once, you can call odbc_fetch_row() with row_number 1, and then continue doing odbc_fetch_row() without row_number to review the result. If a driver doesn't support fetching rows by number, the row_number parameter is ignored.

odbc_field_name
odbc_field_name -- Get the columnname

Description
string odbc_fieldname(int result_id, int field_number);

odbc_field_name() will return the name of the field occupying the given column number in the given ODBC result identifier. Field numbering starts at 1. false is returned on error.

odbc_field_type
odbc_field_type -- datatype of a field

Description
string odbc_field_type(int result_id, int field_number);

odbc_field_type() will return the SQL type of the field referecend by number in the given ODBC result identifier. Field numbering starts at 1.

odbc_field_len
odbc_field_len -- get the Length of a field

Description
string odbc_field_type(int result_id, int field_number);

odbc_field_type() will return the length of the field referecend by number in the given ODBC result identifier. Field numbering starts at 1.

odbc_free_result
odbc_free_result -- free resources associated with a result

Description
int odbc_free_result(int result_id);

Always returns true.

odbc_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 odbc_free_result(), and the memory associated with result_id will be freed.

Note: If auto-commit is disabled (see odbc_autocommit()) and you call odbc_free_result() before commiting, all pending transactions are rolled back.

odbc_longreadlen
odbc_longreadlen -- handling of LONG columns

Description
int odbc_longreadlen(int result_id, int length);

(ODBC SQL types affected: LONG, LONGVARBINARY) The number of bytes returned to PHP is controled by the parameter length. If it is set to 0, Long column data is passed thru to the client.

Note: Handling of LONGVARBINARY columns is also affected by odbc_binmode()

odbc_num_fields
odbc_num_fields -- number of columns in a result

Description
int odbc_num_fields(int result_id);

odbc_num_fields() will return the number of fields (columns) in an ODBC result. This function will return -1 on error. The argument is a valid result identifier returned by odbc_exec().

odbc_pconnect
odbc_pconnect -- Open a persistent database connection

Description
int odbc_pconnect(string dsn, string user, string password);

Returns an ODBC connection id or 0 (false) on error. This function is much like odbc_connect(), except that the connection is not really closed when the script has finished. Future requests for a connection with the same dsn, user, password combination (via odbc_connect() and odbc_pconnect()) can reuse the persistent connection.

Note: Persistent connections have no effect if PHP is used as a CGI program.

For more information on persistent connections, refer to the PHP3 FAQ.

odbc_prepare
odbc_prepare -- Prepares a statement for execution

Description
int odbc_prepare(int connection_id, string query_string);

Returns false on error.

Returns an ODBC result identifier if the SQL command was prepared successfully. The result identifier can be used later to execute the statement with odbc_execute().

odbc_num_rows
odbc_num_rows -- Number of rows in a result

Description
int odbc_num_rows(int result_id);

odbc_num_rows() will return the number of rows in an ODBC result. This function will return -1 on error. For INSERT, UPDATE and DELETE statements odbc_num_rows() returns the number of rows affected. For a SELECT clause this can be the number of rows available.

Note: Using odbc_num_rows() to determine the number of rows available after a SELECT will return -1 with many drivers.

odbc_result
odbc_result -- get result data

Description
string odbc_result(int result_id, mixed field);

Returns the contents of the field.

field can either be an integer containing the column number of the field you want; or it can be a string containing the name of the field. For example:

$item_3 = odbc_result($Query_ID, 3 );
$item_val = odbc_result($Query_ID, "val");
The first call to odbc_result() returns the value of the third field in the current record of the query result. The second function call to odbc_result() returns the value of the field whose field name is "val" in the current record of the query result. An error occurs if a column number parameter for a field is less than one or exceeds the number of columns (or fields) in the current record. Similarly, an error occurs if a field with a name that is not one of the fieldnames of the table(s) that is(are) being queried.

Field indices start from 1. Regarding the way binary or long column data is returned refer to odbc_binmode () and odbc_longreadlen().

odbc_result_all
odbc_result_all -- Print result as HTML table

Description
int odbc_result_all(int result_id, string [format]);

Returns the number of rows in the result or false on error.

odbc_result_all() will print all rows from a result identifier produced by odbc_exec(). The result is printed in HTML table format. With the optional string argument format, additional overall table formatting can be done.

odbc_rollback
odbc_rollback -- Rollback a transaction

Description
int odbc_rollback(int connection_id);

Rolls back all pending statements on connection_id. Returns true on success, false on failure.

XXX. Oracle functions
Table of Contents
Ora_Bind
Ora_Close
Ora_ColumnName
Ora_ColumnType
Ora_Commit
Ora_CommitOff
Ora_CommitOn
Ora_Error
Ora_ErrorCode
Ora_Exec
Ora_Fetch
Ora_GetColumn
Ora_Logoff
Ora_Logon
Ora_Open
Ora_Parse
Ora_Rollback
Ora_Bind
Ora_Bind -- bind a PHP variable to an Oracle parameter

Description
int ora_bind(int cursor, string PHP variable name, string SQL parameter name, int length, int [type]);

Returns true if the bind succeeds, otherwise false. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.

This function binds the named PHP variable with a SQL parameter. The SQL parameter must be in the form ":name". With the optional type parameter, you can define whether the SQL parameter is an in/out (0, default), in (1) or out (2) parameter. As of PHP 3.0.1, you can use the constants ORA_BIND_INOUT, ORA_BIND_IN and ORA_BIND_OUT instead of the numbers.

ora_bind must be called after ora_parse() and before ora_exec(). Input values can be given by assignment to the bound PHP variables, after calling ora_exec() the bound PHP variables contain the output values if available.

<?php
ora_parse($curs, "declare tmp INTEGER; begin tmp := :in; :out := tmp; :x := 7.77; end;");
ora_bind($curs, "result", ":x", $len, 2);
ora_bind($curs, "input", ":in", 5, 1);
ora_bind($curs, "output", ":out", 5, 2);
$input = 765;
ora_exec($curs);
echo "Result: $result<BR>Out: $output<BR>In: $input";
?>
Ora_Close
Ora_Close -- close an Oracle cursor

Description
int ora_close(int cursor);

Returns true if the close succeeds, otherwise false. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.

This function closes a data cursor opened with ora_open().

Ora_ColumnName
Ora_ColumnName -- get name of Oracle result column

Description
string Ora_ColumnName(int cursor, int column);

Returns the name of the field/column column on the cursor cursor. The returned name is in all uppercase letters.

Ora_ColumnType
Ora_ColumnType -- get type of Oracle result column

Description
string Ora_ColumnType(int cursor, int column);

Returns the Oracle data type name of the field/column column on the cursor cursor. The returned type will be one of the following:


"VARCHAR2"
"VARCHAR"
"CHAR"
"NUMBER"
"LONG"
"LONG RAW"
"ROWID"
"DATE"
"CURSOR"

Ora_Commit
Ora_Commit -- commit an Oracle transaction

Description
int ora_commit(int conn);

Returns true on success, false on error. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions. This function commits an Oracle transaction. A transaction is defined as all the changes on a given connection since the last commit/rollback, autocommit was turned off or when the connection was established.

Ora_CommitOff
Ora_CommitOff -- disable automatic commit

Description
int ora_commitoff(int conn);

Returns true on success, false on error. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.

This function turns off automatic commit after each ora_exec().

Ora_CommitOn
Ora_CommitOn -- enable automatic commit

Description
int ora_commiton(int conn);

This function turns on automatic commit after each ora_exec() on the given connection.

Returns true on success, false on error. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.

Ora_Error
Ora_Error -- get Oracle error message

Description
string Ora_Error(int cursor);

Returns an error message of the form XXX-NNNNN where XXX is where the error comes from and NNNNN identifies the error message.

The cursor parameter can as of PHP 3. 0.6 also be a connection id.

On UNIX versions of Oracle, you can find details about an error message like this: $ oerr ora 00001 00001, 00000, "unique constraint (%s.%s) violated" // *Cause: An update or insert statement attempted to insert a duplicate key // For Trusted ORACLE configured in DBMS MAC mode, you may see // this message if a duplicate entry exists at a different level. // *Action: Either remove the unique restriction or do not insert the key

Ora_ErrorCode
Ora_ErrorCode -- get Oracle error code

Description
int Ora_ErrorCode(int cursor);

Returns the numeric error code of the last executed statement on the specified cursor.

The cursor parameter can as of PHP 3. 0.6 also be a connection id.

Ora_Exec
Ora_Exec -- execute parsed statement on an Oracle cursor

Description
int ora_exec(int cursor);

Returns true on success, false on error. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.

Ora_Fetch
Ora_Fetch -- fetch a row of data from a cursor

Description
int ora_fetch(int cursor);

Returns true (a row was fetched) or false (no more rows, or an error occured). If an error occured, details can be retrieved using the ora_error() and ora_errorcode() functions. If there was no error, ora_errorcode() will return 0. Retrieves a row of data from the specified cursor.

Ora_GetColumn
Ora_GetColumn -- get data from a fetched row

Description
mixed ora_getcolumn(int cursor, mixed column);

Returns the column data. If an error occurs, False is returned and ora_errorcode() will return a non-zero value. Note, however, that a test for False on the results from this function may be true in cases where there is not error as well (NULL result, empty string, the number 0, the string "0"). Fetches the data for a column or function result.

Ora_Logoff
Ora_Logoff -- close an Oracle connection

Description
int ora_logoff(int connection);

Returns true on success, False on error. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions. Logs out the user and disconnects from the server.

Ora_Logon
Ora_Logon -- open an Oracle connection

Description
int ora_logon(string user, string password);

Establishes a connection between PHP and an Oracle database with the given username and password.

Connections can be made using SQL*Net by supplying the TNS name to user like this:

$conn = Ora_Logon("user@TNSNAME", "pass");
If you have character data with non-ASCII characters, you should make sure that NLS_LANG is set in your environment. For server modules, you should set it in the server's environment before starting the server.

Returns a connection index on success, or false on failure. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.

Ora_Open
Ora_Open -- open an Oracle cursor

Description
int ora_open(int connection);

Opens an Oracle cursor associated with connection.

Returns a cursor index or False on failure. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.

Ora_Parse
Ora_Parse -- parse an SQL statement

Description
int ora_parse(int cursor_ind, string sql_statement, int defer);

This function parses an SQL statement or a PL/SQL block and associates it with the given cursor. Returns 0 on success or -1 on error.

Ora_Rollback
Ora_Rollback -- roll back transaction

Description
int ora_rollback(int connection);

This function undoes an Oracle transaction. (See ora_commit() for the definition of a transaction.)

Returns true on success, false on error. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.

XXXI. PDF functions
Table of Contents
PDF_get_info
PDF_set_info_creator
PDF_set_info_title
PDF_set_info_subject
PDF_set_info_keywords
PDF_set_info_author
PDF_open
PDF_close
PDF_begin_page
PDF_end_page
PDF_show
PDF_show
PDF_set_font
PDF_set_leading
PDF_set_text_rendering
PDF_set_horiz_scaling
PDF_set_text_rise
PDF_set_text_matrix
PDF_set_text_pos
PDF_set_char_spacing
PDF_set_word_spacing
PDF_continue_text
PDF_stringwidth
PDF_save
PDF_restore
PDF_translate
PDF_scale
PDF_rotate
PDF_setflat
PDF_setlinejoin
PDF_setlinecap
PDF_setmiterlimit
PDF_setlinewidth
PDF_setdash
PDF_moveto
PDF_curveto
PDF_lineto
PDF_circle
PDF_arc
PDF_rect
PDF_closepath
PDF_stroke
PDF_closepath_stroke
PDF_fill
PDF_fill_stroke
PDF_closepath_fill_stroke
PDF_endpath
PDF_clip
PDF_setgray_fill
PDF_setgray_stroke
PDF_setgray
PDF_setrgbcolor_fill
PDF_setrgbcolor_stroke
PDF_setrgbcolor
PDF_add_outline
PDF_set_transition
PDF_set_duration
You can use the pdf functions in PHP to create pdf files if you have the PDF library (available at http://www.ifconnection.de/~tm/) by Thomas Merz. Please consult the excelent documentation for pdflib shipped with the source distribution of pdflib or available at http://www.ifconnection.de/~tm/software/pdflib/PDFlib-0.6.pdf. As long as this documentation is not complete the pdflib documentation should be your first choice. The functions in pdflib and the php3 module have the same name. The parameteres are also identical. You should also understand some of the concepts of pdf to efficiently use this module. The pdf module introduces two new types of variables. They are called pdfdoc and pdfinfo.

PDF_get_info
PDF_get_info -- Returns a default info structure for a pdf document

Description
info pdf_get_info(string filename);

The PDF_get_info() function will return a default info structure for the pdf document. It can be filled with appropriate information like the author, subject etc.

Example 1. PDF_get_info

<?php $info = PDF_get_info();
PDF_set_info_creator($info, "Name of Author") ?>


See also PDF_set_info_creator(), PDF_set_info_subject().

PDF_set_info_creator
PDF_set_info_creator -- Fills the creator field of the info structure

Description
void pdf_set_info_creator(info info, string creator);

The PDF_set_info_creator() function sets the creator of a pdf document. It has to be called after PDF_get_info() and before PDF_open(). Calling it after PDF_open() will have no effect on the document.

Note: This function is not part of the pdf library.

See also PDF_get_info(), PDF_set_info_subject().

PDF_set_info_title
PDF_set_info_title -- Fills the title field of the info structure

Description
void pdf_set_info_title(info info, string title);

The PDF_set_info_title() function sets the title of a pdf document. It has to be called after PDF_get_info() and before PDF_open(). Calling it after PDF_open() will have no effect on the document.

Note: This function is not part of the pdf library.

See also PDF_get_info(), PDF_set_info_xxxxx().

PDF_set_info_subject
PDF_set_info_subject -- Fills the subject field of the info structure

Description
void pdf_set_info_subject(info info, string subject);

The PDF_set_info_subject() function sets the subject of a pdf document. It has to be called after PDF_get_info() and before PDF_open(). Calling it after PDF_open() will have no effect on the document.

Note: This function is not part of the pdf library.

See also PDF_get_info(), PDF_set_info_xxxxx().

PDF_set_info_keywords
PDF_set_info_keywords -- Fills the keywords field of the info structure

Description
void pdf_set_info_keywords(info info, string keywords);

The PDF_set_info_keywords() function sets the keywords of a pdf document. It has to be called after PDF_get_info() and before PDF_open(). Calling it after PDF_open() will have no effect on the document.

Note: This function is not part of the pdf library.

See also PDF_get_info(), PDF_set_info_xxxxx().

PDF_set_info_author
PDF_set_info_author -- Fills the author field of the info structure

Description
void pdf_set_info_author(info info, string author);

The PDF_set_info_author() function sets the author of a pdf document. It has to be called after PDF_get_info() and before PDF_open(). Calling it after PDF_open() will have no effect on the document.

Note: This function is not part of the pdf library.

See also PDF_get_info(), PDF_set_info_xxxxx().

PDF_open
PDF_open -- Opens a new pdf document

Description
int pdf_open(int descripterfile, int info);

The PDF_set_info_author() function opens a new pdf document. The corresponding file has to be opened with fopen() and the file descriptor passed as argument file. info is the an info structure that has to be created with pdf_get_info().

Note: The return value is needed as the first parameter in all other functions writing to the pdf document.

See also fopen(), PDF_get_info().

PDF_close
PDF_close -- Closes the pdf document

Description
void pdf_close(int pdf document);

The PDF_close() function closes the pdf document int.

Note: It will not close the file. You need to call an extra fclose() after pdf_close().

See also PDF_open(), fclose().

PDF_begin_page
PDF_begin_page -- Starts page

Description
void pdf_begin_page(int pdf document, double height, double width);

The PDF_begin_page() function starts a new page with height height and width width.

See also PDF_end_page().

PDF_end_page
PDF_end_page -- Ends page

Description
void pdf_end_page(int pdf document);

The PDF_end_page() function ends a page.

See also PDF_end_page().

PDF_show
PDF_show -- Output text at current position

Description
void pdf_show(int pdf document, string text);

The PDF_show() function outputs the string in text at the current position.

See also PDF_show_xy(), PDF_set_text_pos().

PDF_show
PDF_show -- Output text at position

Description
void pdf_show_xy(int pdf document, string text, double x-koor, double y-koor);

The PDF_show_xy() function outputs the string in text at position with coordinates (x-koor, y-koor).

See also PDF_show().

PDF_set_font
PDF_set_font -- Select the current font face and size

Description
void pdf_set_font(int pdf document, string font name, double size, string encoding);

The PDF_set_font() function sets the the current font face, font size and encoding. You will need to provide the Adobe Font Metrics (afm-files) for the font in the font path (default is ./fonts).

See also PDF_info().

PDF_set_leading
PDF_set_leading -- Sets distance between text lines

Description
void pdf_set leading(int pdf document, double distance);

The PDF_set_leading() function sets the distance between text lines. This will be used if text is output by PDF_continue_text().

See also PDF_continue_text().

PDF_set_text_rendering
PDF_set_text_rendering -- Determines how text is rendered

Description
void pdf_set_text_rendering(int pdf document, int mode);

The PDF_set_text_rendering() function determines how text is rendered. The possible values for mode are 0=fill text, 1=stroke text, 2=fill and stroke text, 3=invisible, 4=fill text and add it to cliping path, 5=stroke text and add it to clipping path, 6=fill and stroke text and add it to cliping path, 7=add it to clipping path.

PDF_set_horiz_scaling
PDF_set_horiz_scaling -- Sets horizontal scaling of text

Description
void pdf_set_horiz_scaling(int pdf document, double scale);

The PDF_set_horiz_scaling() function sets the horizontal scaling to scale percent.

PDF_set_text_rise
PDF_set_text_rise -- Sets the text rise

Description
void pdf_set_text_rise(int pdf document, double value);

The PDF_set_text_rise() function sets the text rising to value units.

PDF_set_text_matrix
PDF_set_text_matrix -- Sets the text matrix

Description
void pdf_set_text_matrix(int pdf document, array matrix);

The PDF_set_text_matrix() function sets a matrix which describes a transformation applied on the current text font.

PDF_set_text_pos
PDF_set_text_pos -- Sets text position

Description
void pdf_set_text_pos(int pdf document, double x-koor, double y-koor);

The PDF_set_text_pos() function sets the position of text for the next pdf_show() function call.

See also PDF_show(), PDF_show_xy().

PDF_set_char_spacing
PDF_set_char_spacing -- Sets character spacing

Description
void pdf_set_char_spacing(int pdf document, double space);

The PDF_set_char_spacing() function sets the spacing between characters.

See also PDF_set_word_spacing(), PDF_set_text_leading().

PDF_set_word_spacing
PDF_set_word_spacing -- Sets spacing between words

Description
void pdf_set_word_spacing(int pdf document, double space);

The PDF_set_word_spacing() function sets the spacing between words.

See also PDF_set_char_spacing(), PDF_set_text_leading().

PDF_continue_text
PDF_continue_text -- Output text in next line

Description
void pdf_continue_text(int pdf document, string text);

The PDF_continue_text() function outputs the string in text in the next line.

See also PDF_show_xy(), PDF_set_text_leading(), PDF_set_text_pos().

PDF_stringwidth
PDF_stringwidth -- Returns width of text in current font

Description
double pdf_stringwidth(int pdf document, string text);

The PDF_stringwidth() function returns the width of the string in text. It requires a font to be set before.

See also PDF_set_font().

PDF_save
PDF_save -- Saves current enviroment

Description
void pdf_save(int pdf document);

The PDF_save() function saves the current enviroment. It works like the postscript command gsave. Very useful if you want to translate or rotate an object without effecting other objects.

See also PDF_restore().

PDF_restore
PDF_restore -- Restores formerly saved enviroment

Description
void pdf_restore(int pdf document);

The PDF_restore() function restores the enviroment saved with PDF_save(). It works like the postscript command grestore. Very useful if you want to translate or rotate an object without effecting other objects.

Example 1. PDF_get_info

<?php PDF_save($pdf);
// do all kinds of rotations, transformations, ...
PDF_restore($pdf) ?>


See also PDF_save().

PDF_translate
PDF_translate -- Sets origin of coordinate system

Description
void pdf_translate(int pdf document, double x-koor, double y-koor);

The PDF_translate() function set the origin of coordinate system to the point (x-koor, y-koor).

PDF_scale
PDF_scale -- Sets scaling

Description
void pdf_scale(int pdf document, double x-scale, double y-scale);

The PDF_scale() function set the scaling factor in both directions.

PDF_rotate
PDF_rotate -- Sets rotation

Description
void pdf_rotate(int pdf document, double angle);

The PDF_rotate() function set the rotation in degress to angle.

PDF_setflat
PDF_setflat -- Sets flatness

Description
void pdf_setflat(int pdf document, double value);

The PDF_setflat() function set the flatness to a value between 0 and 100.

PDF_setlinejoin
PDF_setlinejoin -- Sets linejoin parameter

Description
void pdf_setlinejoin(int pdf document, long value);

The PDF_setlinejoin() function set the linejoin parameter between a value of 0 and 2.

PDF_setlinecap
PDF_setlinecap -- Sets linecap aparameter

Description
void pdf_setlinecap(int pdf document, int value);

The PDF_setlinecap() function set the linecap parameter between a value of 0 and 2.

PDF_setmiterlimit
PDF_setmiterlimit -- Sets miter limit

Description
void pdf_setmiterlimit(int pdf document, double value);

The PDF_setmiterlimit() function set the miter limit to a value greater of equal than 1.

PDF_setlinewidth
PDF_setlinewidth -- Sets line width

Description
void pdf_setlinewidth(int pdf document, double width);

The PDF_setlinewidth() function set the line width to width.

PDF_setdash
PDF_setdash -- Sets dash pattern

Description
void pdf_setdash(int pdf document, double white, double black);

The PDF_setdash() function set the dash pattern white white units and black black units. If both are 0 a solid line is set.

PDF_moveto
PDF_moveto -- Sets current point

Description
void pdf_moveto(int pdf document, double x-koor, double y-koor);

The PDF_moveto() function set the current point to the coordinates x-koor and y-koor.

PDF_curveto
PDF_curveto -- Draws a curve

Description
void pdf_curveto(int pdf document, double x1, double y1, double x2, double y2, double x3, double y3);

The PDF_curveto() function draws a Bezier curve from the current point to the point (x3, y3) using (x1, y1) and (x2, y2) as control points.

See also PDF_moveto(), PDF_lineto().

PDF_lineto
PDF_lineto -- Draws a line

Description
void pdf_lineto(int pdf document, double x-koor, double y-koor);

The PDF_lineto() function draws a line from the current point to the point with coordinates (x-koor, y-koor).

See also PDF_moveto(), PDF_curveto().

PDF_circle
PDF_circle -- Draw a circle

Description
void pdf_circle(int pdf document, double x-koor, double y-koor, double radius);

The PDF_circle() function draws a circle with center at point (x-koor, y-koor) and radius radius.

See also PDF_arc().

PDF_arc
PDF_arc -- Draws an arc

Description
void pdf_arc(int pdf document, double x-koor, double y-koor, double radius, double start, double end);

The PDF_arc() function draws an arc with center at point (x-koor, y-koor) and radius radius, starting at angle start and ending at angle end.

See also PDF_circle().

PDF_rect
PDF_rect -- Draw a rectangle

Description
void pdf_rect(int pdf document, double x-koor, double y-koor, double width, double height);

The PDF_rect() function draws a rectangle with its lower left corner at point (x-koor, y-koor). This width is set to widgth. This height is set to height.

PDF_closepath
PDF_closepath -- Close path

Description
void pdf_closepath(int pdf document);

The PDF_closepath() function closes the current path.

PDF_stroke
PDF_stroke -- Draw line along path

Description
void pdf_stroke(int pdf document);

The PDF_stroke() function draws a line along current path.

See also PDF_closepath(), PDF_closepath_stroke().

PDF_closepath_stroke
PDF_closepath_stroke -- Close path and draw line along path

Description
void pdf_closepath_stroke(int pdf document);

The PDF_closepath_stroke() function is a combination of PDF_closepath() and PDF_stroke(). Than clears the path.

See also PDF_closepath(), PDF_stroke().

PDF_fill
PDF_fill -- Fill current path

Description
void pdf_fill(int pdf document);

The PDF_fill() function fills the interior of the current path with the current fill color.

See also PDF_closepath(), PDF_stroke(), PDF_setgray_fill(), PDF_setgray(), PDF_setrgbcolor_fill(), PDF_setrgbcolor().

PDF_fill_stroke
PDF_fill_stroke -- Fill and stroke current path

Description
void pdf_fill_stroke(int pdf document);

The PDF_fill_stroke() function fills the interior of the current path with the current fill color and draws current path.

See also PDF_closepath(), PDF_stroke(), PDF_fill(), PDF_setgray_fill(), PDF_setgray(), PDF_setrgbcolor_fill(), PDF_setrgbcolor().

PDF_closepath_fill_stroke
PDF_closepath_fill_stroke -- Close, fill and stroke current path

Description
void pdf_closepath_fill_stroke(int pdf document);

The PDF_closepath_fill_stroke() function closes, fills the interior of the current path with the current fill color and draws current path.

See also PDF_closepath(), PDF_stroke(), PDF_fill(), PDF_setgray_fill(), PDF_setgray(), PDF_setrgbcolor_fill(), PDF_setrgbcolor().

PDF_endpath
PDF_endpath -- Ends current path

Description
void pdf_endpath(int pdf document);

The PDF_endpath() function ends the current path but does not close it.

See also PDF_closepath().

PDF_clip
PDF_clip -- Clips to current path

Description
void pdf_clip(int pdf document);

The PDF_clip() function clips all drawing to the current path.

PDF_setgray_fill
PDF_setgray_fill -- Sets filling color to gray value

Description
void pdf_setgray_fill(int pdf document, double value);

The PDF_setgray_fill() function sets the current gray value to fill a path.

See also PDF_setrgbcolor_fill().

PDF_setgray_stroke
PDF_setgray_stroke -- Sets drawing color to gray value

Description
void pdf_setgray_stroke(int pdf document, double gray value);

The PDF_setgray_stroke() function sets the current drawing color to the given gray value.

See also PDF_setrgbcolor_stroke().

PDF_setgray
PDF_setgray -- Sets drawing and filling color to gray value

Description
void pdf_setgray(int pdf document, double gray value);

The PDF_setgray_stroke() function sets the current drawing and filling color to the given gray value.

See also PDF_setrgbcolor_stroke(), PDF_setrgbcolor_fill().

PDF_setrgbcolor_fill
PDF_setrgbcolor_fill -- Sets filling color to rgb color value

Description
void pdf_setrgbcolor_fill(int pdf document, double red value, double green value, double blue value);

The PDF_setrgbcolor_fill() function sets the current rgb color value to fill a path.

See also PDF_setrgbcolor_fill().

PDF_setrgbcolor_stroke
PDF_setrgbcolor_stroke -- Sets drawing color to rgb color value

Description
void pdf_setrgbcolor_stroke(int pdf document, double red value, double green value, double blue value);

The PDF_setrgbcolor_stroke() function sets the current drawing color to the given rgb color value.

See also PDF_setrgbcolor_stroke().

PDF_setrgbcolor
PDF_setrgbcolor -- Sets drawing and filling color to rgb color value

Description
void pdf_setrgbcolor(int pdf document, double red value, double green value, double blue value);

The PDF_setrgbcolor_stroke() function sets the current drawing and filling color to the given rgb color value.

See also PDF_setrgbcolor_stroke(), PDF_setrgbcolor_fill().

PDF_add_outline
PDF_add_outline -- Adds bookmark for current page

Description
void pdf_add_outline(int pdf document, string text);

The PDF_add_outline() function adds a bookmark with text text that points to the current page.

PDF_set_transition
PDF_set_transition -- Sets transition between pages

Description
void pdf_set_transition(int pdf document, int transition);

The PDF_set_transition() function set the transition between following pages. The value of transition can be 0 for none, 1 for two lines sweeping across the screen reveal the page, 2 for multiple lines sweeping across the screen reveal the page, 3 for a box reveals the page, 4 for a single line sweeping across the screen reveals the page, 5 for the old page dissolves to reveal the page, 6 for the dissolve effect moves from one screen edge to another, 7 for the old page is simply replaced by the new page (default)

PDF_set_duration
PDF_set_duration -- Sets duration between pages

Description
void pdf_set_duration(int pdf document, double duration);

The PDF_set_duration() function set the duration between following pages in seconds.

XXXII. PostgreSQL functions
Table of Contents
pg_Close
pg_cmdTuples
pg_Connect
pg_DBname
pg_ErrorMessage
pg_Exec
pg_Fetch_Array
pg_Fetch_Object
pg_Fetch_Row
pg_FieldIsNull
pg_FieldName
pg_FieldNum
pg_FieldPrtLen
pg_FieldSize
pg_FieldType
pg_FreeResult
pg_GetLastOid
pg_Host
pg_loclose
pg_locreate
pg_loopen
pg_loread
pg_loreadall
pg_lounlink
pg_lowrite
pg_NumFields
pg_NumRows
pg_Options
pg_pConnect
pg_Port
pg_Result
pg_tty
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 6.3.2 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


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");

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")
?>


pg_Close
pg_Close -- closes a PostgreSQL connection

Description
bool pg_close(int connection);

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.

pg_cmdTuples
pg_cmdTuples -- returns number of affected tuples

Description
int pg_cmdtuples(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.

Example 1. pg_cmdtuples

<?php
$result = pg_exec($conn, "INSERT INTO verlag VALUES ('Autor')");
$cmdtuples = pg_cmdtuples($result);
echo $cmdtuples . " <- cmdtuples affected.";
?>


pg_Connect
pg_Connect -- opens a connection

Description
int pg_connect(string host, string port, string options, string tty, string dbname);

Returns a connection index on success, or false if the connection could not be made. Opens a connection to a PostgreSQL database. Each of the arguments should be a quoted string, 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.

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 and options.

See also pg_pConnect().

pg_DBname
pg_DBname -- database name

Description
string pg_dbname(int connection);

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.

pg_ErrorMessage
pg_ErrorMessage -- error message

Description
string pg_errormessage(int connection);

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 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.

pg_Exec
pg_Exec -- execute a query

Description
int pg_exec(int connection, string query);

Returns a result index if query could be executed, false on failure or if connection is not a valid connection index. Details about the error can be retrieved using the pg_ErrorMessage() function if connection is valid. Sends an SQL statement to the PostgreSQL database specified by the connection index. The connection must be a valid 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.

Note: PHP2 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 PHP3.

pg_Fetch_Array
pg_Fetch_Array -- fetch row as array

Description
array pg_fetch_array(int result, int row);

Returns: An array that corresponds to the fetched row, or 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 of the result array, it also stores the data in associative indices, using the field names as keys.

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.

For further details, also see pg_fetch_row()


Example 1. PostgreSQL fetch array

<?php
$conn = pg_pconnect("","","","","publisher");
if (!$conn) {
echo "An error occured.\n";
exit;
}

$result = pg_Exec ($conn, "SELECT * FROM authors");
if (!$result) {
echo "An error occured.\n";
exit;
}

$arr = pg_fetch_array ($result, 0);
echo $arr[0] . " <- array\n";

$arr = pg_fetch_array ($result, 1);
echo $arr["author"] . " <- array\n";
?>


pg_Fetch_Object
pg_Fetch_Object -- fetch row as object

Description
object pg_fetch_object(int result, int row);

Returns: An object with properties that correspond to the fetched 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).

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().

Example 1. Postgres fetch object

<?php
$database = "verlag";
$db_conn = pg_connect ("localhost", "5432", "", "", $database);
if (!$db_conn): ?>
<H1>Failed connecting to postgres database <? echo $database ?></H1> <?
exit;
endif;

$qu = pg_exec ($db_conn, "SELECT * FROM verlag ORDER BY autor");
$row = 0; // postgres needs a row counter other dbs might not

while ($data = pg_fetch_object ($qu, $row)):
echo $data->autor." (";
echo $data->jahr ."): ";
echo $data->titel."<BR>";
$row++;
endwhile; ?>

<PRE><?
$fields[] = Array ("autor", "Author");
$fields[] = Array ("jahr", " Year");
$fields[] = Array ("titel", " Title");

$row= 0; // postgres needs a row counter other dbs might not
while ($data = pg_fetch_object ($qu, $row)):
echo "----------\n";
reset ($fields);
while (list (,$item) = each ($fields)):
echo $item[1].": ".$data->$item[0]."\n";
endwhile;
$row++;
endwhile;
echo "----------\n"; ?>
</PRE>


pg_Fetch_Row
pg_Fetch_Row -- get row as enumerated array

Description
array pg_fetch_row(int result, int row);

Returns: An array that corresponds to the fetched row, or false 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.

Subsequent call to pg_fetch_row() would return the next row in the result set, or false if there are no more rows.

See also: pg_fetch_array(), pg_fetch_object(), pg_result().

Example 1. Postgres fetch row

<?php
$conn = pg_pconnect("","","","","publisher");
if (!$conn) {
echo "An error occured.\n";
exit;
}

$result = pg_Exec ($conn, "SELECT * FROM authors");
if (!$result) {
echo "An error occured.\n";
exit;
}

$row = pg_fetch_row ($result, 0);
echo $row[0] . " <- row\n";

$row = pg_fetch_row ($result, 1);
echo $row[0] . " <- row\n";

$row = pg_fetch_row ($result, 2);
echo $row[1] . " <- row\n";
?>


pg_FieldIsNull
pg_FieldIsNull -- Test if a field is NULL

Description
int pg_fieldisnull(int result_id, int row, mixed field);

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.

pg_FieldName
pg_FieldName -- Returns the name of a field

Description
string pg_fieldname(int result_id, 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_FieldNum
pg_FieldNum -- Returns the number of a column

Description
int pg_fieldnum(int result_id, 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_FieldPrtLen
pg_FieldPrtLen -- Returns the printed length

Description
int pg_fieldprtlen(int result_id, int row_number, 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_FieldSize
pg_FieldSize -- Returns the internal storage size of the named field

Description
int pg_fieldsize(int result_id, string field_name);

pg_FieldSize() will return the internal storage size (in bytes) of the named field in the given PostgreSQL result. A field size of -1 indicates a variable length field. This function will return false on error.

pg_FieldType
pg_FieldType -- Returns the type name for the corresponding field number

Description
int pg_fieldtype(int result_id, 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_FreeResult
pg_FreeResult -- Frees up memory

Description
int pg_freeresult(int result_id);

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 identifier as an argument and the associated result memory will be freed.

pg_GetLastOid
pg_GetLastOid -- Returns the last object identifier

Description
int pg_getlastoid(int result_id);

pg_GetLastOid() can be used to retrieve the Oid assigned to an inserted tuple if the result identifier is used from the last command sent via pg_Exec() 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.

pg_Host
pg_Host -- Returns the host name

Description
string pg_host(int connection_id);

pg_Host() will return the host name of the given PostgreSQL connection identifier is connected to.

pg_loclose
pg_loclose -- close a large object

Description
void pg_loclose(int fd);

pg_loclose() closes an Inversion Large Object. fd is a file descriptor for the large object from pg_loopen().

pg_locreate
pg_locreate -- create a large object

Description
int pg_locreate(int conn);

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).

pg_loopen
pg_loopen -- open a large object

Description
int pg_loopen(int conn, int objoid, string mode);

pg_loopen() open an Inversion Large Object and returns file descriptor of the large object. The file descriptor 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".

pg_loread
pg_loread -- read a large object

Description
string pg_loread(int fd, int len);

pg_loread() reads at most len bytes from a large object and returns it as a string. fd specifies a valid large object file descriptor andlen specifies the maximum allowable size of the large object segment.

pg_loreadall
pg_loreadall -- read a entire large object

Description
void pg_loreadall(int fd);

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.

pg_lounlink
pg_lounlink -- delete a large object

Description
void pg_lounlink(int conn, int lobjid);

pg_lounlink() deletes a large object with the lobjid identifier for that large object.

pg_lowrite
pg_lowrite -- write a large object

Description
int pg_lowrite(int fd, string buf);

pg_lowrite() writes at most to a large object 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().

pg_NumFields
pg_NumFields -- Returns the number of fields

Description
int pg_numfields(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_NumRows
pg_NumRows -- Returns the number of rows

Description
int pg_numrows(int result_id);

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.

pg_Options
pg_Options -- Returns options

Description
string pg_options(int connection_id);

pg_Options() will return a string containing the options specified on the given PostgreSQL connection identifier.

pg_pConnect
pg_pConnect -- make a persistent database connection

Description
int pg_pconnect(string host, string port, string options, string tty, string dbname);

Returns a connection index on success, or false if the connection could not be made. Opens a persistent connection to a PostgreSQL database. Each of the arguments should be a quoted string, 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 persistent connections open at once. See also 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 and options.

pg_Port
pg_Port -- Returns the port number

Description
int pg_port(int connection_id);

pg_Port() will return the port number that the given PostgreSQL connection identifier is connected to.

pg_Result
pg_Result -- Returns values from a result identifier

Description
mixed pg_result(int result_id, int row_number, mixed fieldname);

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.

PostgreSQL has many built in types and only the basic ones are directly supported here. All forms of integer, boolean and oid types are returned as integer values. All forms of float, and 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.

pg_tty
pg_tty -- Returns the tty name

Description
string pg_tty(int connection_id);

pg_tty() will return the tty name that server side debugging output is sent to on the given PostgreSQL connection identifier.

XXXIII. Regular expression functions
Table of Contents
ereg
ereg_replace
eregi
eregi_replace
split
sql_regcase
ereg
ereg -- regular expression match

Description
int ereg(string pattern, string string, array [regs]);

Searchs string for matches to the regular expression given in pattern.

If matches are found for parenthesized substrings of pattern and the function is called with the third argument regs, the matches will be stored in the elements of regs. $regs[1] will contain the substring which starts at the first left parenthesis; $regs[2] will contain the substring starting at the second, and so on. $regs[0] will contain a copy of string.

Searching is case sensitive.

Returns true if a match for pattern was found in string, or false if no matches were found or an error occurred.

The following code snippet takes a date in ISO format (YYYY-MM-DD) and prints it in DD.MM.YYYY format:

Example 1. ereg() example

if ( ereg( "([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs ) ) {
echo "$regs[3].$regs[2].$regs[1]";
} else {
echo "Invalid date format: $date";
}


See also eregi(), ereg_replace(), and eregi_replace().

ereg_replace
ereg_replace -- replace regular expression

Description
string ereg_replace(string pattern, string replacement, string string);

This function scans string for matches to pattern, then replaces the matched text with replacement.

If pattern contains parenthesized substrings, replacement may contain substrings of the form \\digit, which will be replaced by the text matching the digit'th parenthesized substring; \\0 will produce the entire contents of string. Up to nine substrings may be used. Parentheses may be nested, in which case they are counted by the opening parenthesis. For example, the following code snippet prints "This was a test" three times:

Example 1. ereg_replace() example

$string = "This is a test";
echo ereg_replace( " is", " was", $string );
echo ereg_replace( "( )is", "\\1was", $string );
echo ereg_replace( "(( )is)", "\\2was", $string );


See also ereg(), eregi(), and eregi_replace().

eregi
eregi -- case insensitive regular expression match

Description
int eregi(string pattern, string string, array [regs]);

This function is identical to ereg() save that this ignores case distinction when matching alphabetic characters.

See also ereg(), ereg_replace(), and eregi_replace().

eregi_replace
eregi_replace -- replace regular expression case insensitive

Description
string eregi_replace(string pattern, string replacement, string string);

This function is identical to ereg_replace() save that this ignores case distinction when matching alphabetic characters.

See also ereg(), eregi(), and ereg_replace().

split
split -- split string into array by regular expression

Description
array split(string pattern, string string, int [limit]);

Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by pattern. If an error occurs, returns false.

To get the first five fields from a line from /etc/passwd:

Example 1. split() example

$passwd_list = split( ":", $passwd_line, 5 );


Note that pattern is case-sensitive.

See also: explode() and implode().

sql_regcase
sql_regcase -- make regular expression for case insensitive match

Description
string sql_regcase(string string);

Returns a valid regular expression which will match string, ignoring case. This expression is string with each character converted to a bracket expression; this bracket expression contains that character's uppercase and lowercase form if applicable, otherwise it contains the original character twice.

Example 1. sql_regcase() example

echo sql_regcase( "Foo bar" );


prints

[Ff][Oo][Oo][ ][Bb][Aa][Rr]
.

This can be used to achieve case insensitive pattern matching in products which support only case sensitive regular expressions.

XXXIV. Semaphore and Shared Memory Functions
Table of Contents
sem_get
sem_acquire
sem_release
shm_attach
shm_detach
shm_put_var
shm_put_var
shm_remove_var
shm_remove
This module provides semaphore functions using System V semaphores. Semaphores may be used to provide exclusive access to resources on the current machine, or to limit the number of processes that may simultaneously use a resource.

Shared memory support is also included. It is compatible with System V compatible systems.

sem_get
sem_get -- get a semaphore id

Description
int sem_get(int key, int [max_acquire] , int [perm] );

Returns: A positive semaphore identifier on success, or false on error.

sem_get() returns an id that can be used to access the System V semaphore with the given key. The semaphore is created if necessary using the permission bits specified in perm (defaults to 0666). The number of processes that can acquire the semaphore simultaneously is set to max_acquire (defaults to 1). Actually this value is set only if the process finds it is the only process currently attached to the semaphore.

A second call to sem_get() for the same key will return a different semaphore identifier, but both identifiers access the same underlying semaphore.

See also: sem_acquire() and sem_release().

sem_acquire
sem_acquire -- acquire a semaphore

Description
int sem_acquire(int sem_identifier);

Returns: true on success, false on error

sem_acquire() blocks (if necessary) until the semaphore can be acquired. A process attempting to acquire a semaphore which it has already acquired will block forever if acquiring the semaphore would cause its max_acquire value to be exceeded.

After processing a request, any semaphores acquired by the process but not explicitly released will be released automatically and a warning will be generated.

See also: sem_get() and sem_release().

sem_release
sem_release -- release a semaphore

Description
int sem_release(int sem_identifier);

Returns: true on success, false on error

sem_release() releases the semaphore if it is currently acquired by the calling process, otherwise a warning is generated.

After releasing the semaphore, sem_acquire() may be called to re-acquire it.

See also: sem_get() and sem_acquire().

shm_attach
shm_attach -- Creates or open a shared memory

Description
int shm_attach(long key, long memsize, long perm);

Creates or open a shared memory with the given key and memsize.

shm_detach
shm_detach -- Disconnects from shared memory

Description
int shm_detach(long id);

Disconnects from shared memory with the given id created from shm_attach(). Remember, that the shared memory still exist in the Unix system and the data is still present.

shm_put_var
shm_put_var -- Inserts or updates a variable in shared memory

Description
int shm_put_var(int id, long variable_key, mixed variable);

Inserts or updates a variable with a given variable_key. All variable-types (double, long, string, array) are supported. The function serialize() can be used to store the data.

shm_put_var
shm_put_var -- Reads a variable with a given variable_key

Description
mixed shm_get_var(int id, long variable_key);

Reads a variable with a given variable_key. The variable is still present in the shared memory. The function unserialize() can be used to decode the data.

shm_remove_var
shm_remove_var -- Removes a variable from shared memory

Description
int shm_remove_var(int id, long variable_key);

Removes a variable with a given variable_key from shared memory.

shm_remove
shm_remove -- Removes shared memory

Description
int shm_remove(long key);

Removes shared memory from the Unix system. All data will be destroyed.

PHP热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号