Interface for PHP to DB2 for z/OS, DB2 for LUW. Db2 for IBM i support is deprecated.
The minimum PHP version supported by driver is PHP 7.3 and the latest version supported is PHP 8.2.
CLI driver MUST be installed in your system. You can find and download the latest versions from here.
php, gcc, make and tar should be installed in your system.
You may not find gcc, make, tar in some of the docker images (like Amazon Linux2).
In such cases use below command to install gcc, etc.
yum install make gccNOTICE: IBM recommends that if you are working on a new Db2 for IBM i connection, you MUST use the PDO_ODBC or the ODBC extensions instead with the ODBC Driver for IBM i Access Client Solutions.
If you are using this extension with an existing connection running on IBM i, IBM_DB2 doesn't link with the Db2 LUW client
library, but instead with libdb400, which provides a PASE wrapper for SQL/CLI. The differences between SQL/CLI in IBM i and
the LUW driver are wrapped for you. You don't need Db2 Connect on IBM i as a result.
To install, make sure you have the new Yum-based OSS environment. Install PHP, plus any dependencies like so:
yum install sqlcli-devel gcc make-gnuTony Cairns' replacement libdb400 is not yet tested, but may be desirable due to its greater debugging features.
If IBM_DB_HOME and LD_LIBRARY_PATH environment variable not set then set them with installed CLIDRIVER.
(say CLIDRIVER installed at /home/user/clidriver)
export IBM_DB_HOME=/home/user/clidriver
export LD_LIBRARY_PATH="${IBM_DB_HOME}/lib"
export PATH="${IBM_DB_HOME}/bin":$PATHIn case of Docker (Example Amazon Linux2), execute db2level command in your command prompt. If any error comes then install
pam from package manager:
yum install pam-
Install this extension:
pecl install ibm_db2
-
Open the
php.inifile in an editor of your choice. Edit the extension entry in thephp.inifile in the<local_php_directory>/php/libdirectory to reference the PHP driver:extension=ibm_db2.so -
Ensure that the PHP driver can access the
libdb2.soCLI driver file by setting theLD_LIBRARY_PATHvariable for Linux and UNIX operating systems other than the AIX® operating system. For AIX operating system, you must setLIBPATHvariable. -
Optional: If the PHP application that is connecting to an IBM database server is running ini the HTTP server environment, add the
LD_LIBRARY_PATHvariable in thehttpd.conffile.
-
Add the
CLIDRIVER\binpath to thePATHenvironment variable like so (for a batch file):set PATH=<CLIDRIVER installed path>\bin;%PATH% -
Download the DLLs for PHP 7.x and 8.x from the ibmdb repository. Select the build for the PHP that matches the version, architecture, and thread model.
-
Open the
php.inifile in an editor of your choice. Edit the extension entry in thephp.inifile in the<local_php_directory>\php\libdirectory to reference the driver:extension=php_ibm_db2
Create a connect.php script with the following content:
<?php
$database = 'dsn name';
$user = 'user';
$password = 'password';
$conn = db2_connect($database, $user, $password);
if ($conn) {
echo 'Connection succeeded.';
db2_close($conn);
} else {
echo 'Connection failed: ' . db2_conn_errormsg();
}
?>Run the sample program:
php connect.php-
Download Source code from https://pecl.php.net/package/ibm_db2
-
Extract the source archive
-
Run the following commands from the extracted directory:
phpize --clean phpize ./configure --with-IBM_DB2=/home/user/clidriver make make install
This blog mentions how to build php ibm_db2 from source in Windows.
make test is adequate for most tests except those involving XMLSERVICE.
For more complex tests, use run-tests.php and set TEST_PHP_ARGS as needed.
Many tests rely on having libraries like DB2 added. On IBM i, create schema
instead of crtlib is recommended to properly set up things like journals.
Please let us know if there are any hardcoded library names; we've tried to
clean up usage of them when not documented.
If you have strange failures during the tests, you might want to adjust the
autocommit setting. ibm_db2.i5_allow_commit=1 is tested to work.
On IBM i, you might want to use *LOCAL as your DSN without a username or
password. This means you won't need to provide another account for most tests.
Modify tests/connection.inc to do so.
On IBM i, it's strongly recommended to set QCCSID to a reasonable value, not
65535. Without setting this, you will have many string values failing to
convert from EBCDIC. IBM_DB2 provides a workaround for this nowadays due to
the amount of systems in the wild without a properly set QCCSID, but you
should do this anyways. To check and set QCCSID, run WRKSYSVAL from a 5250.
See CONTRIBUTING.md.
The developer sign-off should include the reference to the DCO in defect remarks, like in this example:
DCO 1.1 Signed-off-by: Random J Developer <random@developer.org>