Podręcznik PHP
Poprzedni |  | Następny

# LV. IBM DB2, Cloudscape and Apache Derby Functions

# Wstęp

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

# Wymagania

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.

## Requirements on Linux or Unix

The user invoking the PHP executable or SAPI must specify the DB2 instance before accessing these functions. You can set the name of the DB2 instance in `php.ini` using the ibm_db2.instance_name configuration option, or you can source the DB2 instance profile before invoking the PHP executable.

If you created a DB2 instance named db2inst1 in `/home/db2inst1/`, for example, you can add the following line to `php.ini`:

    ibm_db2.instance_name=db2inst1

If you do not set this option in `php.ini`, 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 either set the ibm_db2.instance_name configuration option in `php.ini`, or source the DB2 instance environment in your Web server start script (typically `/etc/init.d/httpd` or `/etc/init.d/apache`).

# Instalacja

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. The header files are included with the DB2 Application Development Client freely available for download from the IBM DB2 Universal Database support site.

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 Rozdział 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`.

# Konfiguracja czasu wykonywania

Na działanie tych funcji wpływają ustawienia zawarte w pliku `php.ini`.

Tabela 1. ibm_db2 Opcje konfigurowalne

Nazwa | Domyślne | Zmienialne | Changelog
--- | --- | --- | ---
ibm_db2.binmode | "1" | PHP_INI_ALL |
ibm_db2.instance_name | NULL | PHP_INI_SYSTEM |

Oto krótkie wyjaśnienie dyrektyw konfiguracji.

ibm_db2.binmode integer

  This option controls the mode used for converting to and from binary data in the PHP application.

  - 1 (DB2_BINARY)

  - 2 (DB2_CONVERT)

  - 3 (DB2_PASSTHRU)

ibm_db2.instance_name string

  On Linux and UNIX operating systems, this option defines the name of the instance to use for cataloged database connections. If this option is set, its value overrides the DB2INSTANCE environment variable setting.

  This option is ignored on Windows operating systems.

# Stałe predefinopwane

Poniższe stałe są zdefiniowane w tym rozszerzeniu i stają się dostępne, gdy rozszerzenie jest dokompilowane do PHP, lub załadowane dynamicznie przy starcie.

`DB2_BINARY` (integer)

  Specifies that binary data shall be returned as is. This is the default mode.

`DB2_CONVERT` (integer)

  Specifies that binary data shall be converted to a hexadecimal encoding and returned as an ASCII string.

`DB2_PASSTHRU` (integer)

  Specifies that binary data shall be converted to a `NULL` value.

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

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

`DB2_CASE_NATURAL` (integer)

  Specifies that column names will be returned in their natural case.

`DB2_CASE_LOWER` (integer)

  Specifies that column names will be returned in lower case.

`DB2_CASE_UPPER` (integer)

  Specifies that column names will be returned in upper case.

# Typy zasobów

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

Poprzedni | Spis treści | Następny
hw_api->userlist | Początek rozdziału | db2_autocommit