<< Back to man.ChinaUnix.net

XLVII. IBM DB2, Cloudscape and Apache Derby Functions

简介

These functions enable you to access IBM DB2 Universal Database, IBM Cloudscape, and Apache Derby databases using the DB2 Call Level Interface (DB2 CLI).

需求

To connect to IBM DB2 Universal Database for Linux, UNIX, and Windows, or IBM Cloudscape, or Apache Derby, you must install an IBM DB2 Universal Database client on the same computer on which you are running PHP. The extension has been developed and tested with DB2 Version 8.2.

To connect to IBM DB2 Universal Database for z/OS or iSeries, you also require IBM DB2 Connect or the equivalent DRDA gateway software.

On Linux or Unix operating systems, ensure that the user invoking the PHP executable or SAPI has sourced the DB2 instance environment before accessing these functions. If you created a DB2 instance in /home/db2inst1/, for example, you must issue the following command to modify your environment variables to enable access to DB2:
bash$ source /home/db2inst1/sqllib/db2profile
To enable your PHP-enabled Web server to access these functions, you must add the same command to your Web server start script (typically /etc/init.d/httpd or /etc/init.d/apache).

安装

To build the ibm_db2 extension, the DB2 application development header files and libraries must be installed on your system. DB2 does not install these by default, so you may have to return to your DB2 installer and add this option.

If you add the DB2 application development header files and libraries to a Linux or Unix operating system on which DB2 was already installed, you must issue the command db2iupdt -e to update the symbolic links to the header files and libraries in your DB2 instances.

ibm_db2 is a PECL extension, so follow the instructions in µÚ 7 章 to install the ibm_db2 extension for PHP. Issue the configure command to point to the location of your DB2 header files and libraries as follows:
bash$ ./configure --with-IBM_DB2=/path/to/DB2
The configure command defaults to /opt/IBM/db2/V8.1.

预定义常量

以下常量由本扩展模块定义,因此只有在本扩展模块被编译到 PHP 中,或者在运行时被动态加载后才有效。

DB2_BINARY (integer)

DB2_CONVERT (integer)

DB2_PASSTHRU (integer)

DB2_SCROLLABLE (integer)

Specifies a scrollable cursor for a statement resource. This mode enables random access to rows in a result set, but currently is supported only by IBM DB2 Universal Database.

DB2_FORWARD_ONLY (integer)

Specifies a forward-only cursor for a statement resource. This is the default cursor type and is supported on all database servers.

DB2_PARAM_IN (integer)

Specifies the PHP variable should be bound as an IN parameter for a stored procedure.

DB2_PARAM_OUT (integer)

Specifies the PHP variable should be bound as an OUT parameter for a stored procedure.

DB2_PARAM_INOUT (integer)

Specifies the PHP variable should be bound as an INOUT parameter for a stored procedure.

DB2_PARAM_FILE (integer)

Specifies that the column should be bound directly to a file for input or output.

DB2_AUTOCOMMIT_ON (integer)

Specifies that autocommit should be turned on.

DB2_AUTOCOMMIT_OFF (integer)

Specifies that autocommit should be turned off.

DB2_DOUBLE (integer)

Specifies that the variable should be bound as a DOUBLE, FLOAT, or REAL data type.

DB2_LONG (integer)

Specifies that the variable should be bound as a SMALLINT, INTEGER, or BIGINT data type.

DB2_CHAR (integer)

Specifies that the variable should be bound as a CHAR or VARCHAR data type.

资源类型

The ibm_db2 extension returns connection resources, statement resources, and result set resources.

目录
db2_autocommit --  Returns or sets the AUTOCOMMIT state for a database connection
db2_bind_param --  Binds a PHP variable to an SQL statement parameter
db2_close --  Closes a database connection
db2_column_privileges --  Returns a result set listing the columns and associated privileges for a table
db2_columns --  Returns a result set listing the columns and associated metadata for a table
db2_commit --  Commits a transaction
db2_conn_error --  Returns a string containing the SQLSTATE returned by the last connection attempt
db2_conn_errormsg --  Returns the last connection error message and SQLCODE value
db2_connect --  Returns a connection to a database
db2_cursor_type --  Returns the cursor type used by a statement resource
db2_exec --  Executes an SQL statement directly
db2_execute --  Executes a prepared SQL statement
db2_fetch_assoc --  Returns an array, indexed by column name, representing a row in a result set
db2_fetch_both --  Returns an array, indexed by both column name and position, representing a row in a result set
db2_fetch_into --  Returns an array, indexed by column position, representing a row in a result set
db2_fetch_row --  Sets the result set pointer to the next row or requested row
db2_field_display_size --  Returns the maximum number of bytes required to display a column
db2_field_name --  Returns the name of the column in the result set
db2_field_num --  Returns the position of the named column in a result set
db2_field_precision --  Returns the precision of the indicated column in a result set
db2_field_scale --  Returns the scale of the indicated column in a result set
db2_field_type --  Returns the data type of the indicated column in a result set
db2_field_width --  Returns the width of the current value of the indicated column in a result set
db2_foreign_keys --  Returns a result set listing the foreign keys for a table
db2_free_result --  Frees resources associated with a result set
db2_free_stmt --  Frees resources associated with the indicated statement resource
db2_next_result --  Requests the next result set from a stored procedure
db2_num_fields --  Returns the number of fields contained in a result set
db2_num_rows --  Returns the number of rows affected by an SQL statement
db2_pconnect --  Returns a persistent connection to a database
db2_prepare --  Prepares an SQL statement to be executed
db2_primary_keys --  Returns a result set listing primary keys for a table
db2_procedure_columns --  Returns a result set listing the input and output parameters for a stored procedure
db2_procedures --  Returns a result set listing the stored procedures registered in a database
db2_result --  Returns a single column from a row in the result set
db2_rollback --  Rolls back a transaction
db2_special_columns --  Returns a result set listing the unique row identifier columns for a table
db2_statistics --  Returns a result set listing the index and statistics for a table
db2_stmt_error --  Returns a string containing the SQLSTATE returned by an SQL statement
db2_stmt_errormsg --  Returns a string containing the last SQL statement error message
db2_table_privileges --  Returns a result set listing the tables and associated privileges in a database
db2_tables --  Returns a result set listing the tables and associated metadata in a database