Before you can connect to an IBM® database server and run SQL statements, you
must set up the PHP environment.
Before you begin
You
must have the following required software installed on your system:
- PHP version 5 or later
- If your PHP application connects to a remote IBM database, the computer that runs your PHP
application requires one of the following products:
- The IBM Data Server
Client product
- The IBM Data Server Runtime
Client product
- The
IBM Data Server Driver Package product
- The IBM Data Server Driver for
ODBC and CLI product
If your PHP application connects to an IBM database server on the local computer, no
additional IBM data server products
are required.
Procedure
To install the ibm_db2 and pdo_ibm php extensions:
- Using the export command, set the environment variable
IBM_DB_HOME.
$export IBM_DB_HOME=DB2HOME
The DB2HOME is the directory where the IBM Data Server
product is installed. For example:
$ export IBM_DB_HOME=/home/db2inst1/sqllib
- Using one of the following three methods, install the ibm_db
and pdo_ibm extensions.
- Use the pecl install command included in
the PHP Extension Community Library (PECL).
- To install the ibm_db2 extension:
$ pecl install ibm_db2
- To install the pdo_ibm extension:
$ pecl install pdo_ibm
- Use the commands included in the source code:
- Extract the source archive.
- Run the following commands from the extracted directory:
$ phpize --clean
$ phpize
$ ./configure
$ make
$ make install
- If you are installing the pdo_ibm extension, you must run the
following configure command:
$./configure --with-PDO_IBM=DB2HOME
The
DB2HOME variable is the directory where the IBM Data Server product is installed.
- Use the compiled extensions included with the IBM Data Server products:
- You must determine whether your PHP environment is threadsafe
or not threadsafe by issuing the following command:
$ php -info| grep "Thread Safe"
- The IBM data server client
and
IBM Data Server Driver Package software
are shipped with two types of PHP drivers:
- Threadsafe: ibm_db2_XX_ts.so and pdo_ibm_XX_ts.so
- Not threadsafe: ibm_db2_XX_nts.so and pdo_ibm_XX_nts.so
Using the cp command, copy the appropriate
PHP driver share library files to the installed PHP extension directory as ibm_db2.so and pdo_ibm.so files.For
a 32-bit PHP driver:
$ cp DB2HOME/php/php32/ibm_db2_XX_[ts/nts].so <local_php_directory>/php/lib/php/extensions/ibm_db2.so
$ cp DB2HOME/php/php32/pdo_ibm_XX_[ts/nts].so <local_php_directory>/php/lib/php/extensions/pdo_ibm.so
For a 64-bit PHP driver:
$ cp DB2HOME/php/php64/ibm_db2_XX_[ts/nts].so <local_php_directory>/php/lib/php/extensions/ibm_db2.so
$ cp DB2HOME/php/php64/pdo_ibm_XX_[ts/nts].so <local_php_directory>/php/lib/php/extensions/pdo_ibm.so
The DB2HOME variable is the directory where the IBM Data Server product is installed.
- Open the php.ini file in an editor
of your choice. Edit the extension entry in the php.ini file
in the <local_php_directory>/php/lib directory
to reference the PHP driver:
extension=pdo.so
extension=ibm_db2.so
extension=pdo_ibm.so
-
Ensure that the PHP driver can access the libdb2.so CLI driver
file by setting the LD_LIBRARY_PATH variable for Linux and UNIX operating
systems other than the AIX operating system. For AIX operating system,
you must set LIBPATH variable.
- For a 32-bit Linux and UNIX operating systems other than the AIX
operating system, use the export command to set
the IBM_DB_HOME/lib32 directory
to the LD_LIBRARY_PATH variable.
export LD_LIBRARY_PATH=DB2HOME/lib32
- For a 32-bit AIX operating system, use the export command
to set the IBM_DB_HOME/lib32 directory
to the: LIBPATH variable.
export LIBPATH=DB2HOME/lib32
- For a 64-bit Linux and UNIX operating systems other than the AIX
operating system, use the export command to set
the LD_LIBRARY_PATH variable to the IBM_DB_HOME/lib64 directory.
export LD_LIBRARY_PATH=DB2HOME/lib64
- For a 64-bit AIX operating system, use the export command
to set the LD_LIBRARY_PATH variable to the IBM_DB_HOME/lib64 directory.
export LIBPATH=DB2HOME/lib64
- Optional: If the PHP application that is connecting
to an IBM database server is
running in the HTTP server environment:
- Add the LD_LIBRARY_PATH variable in the httpd.conf or
httpd.service file.
For a 32-bit architecture, set LD_LIBRARY_PATH to the DB2HOME\lib32
directory. For a 64-bit architecture set LD_LIBRARY_PATH to the DB2HOME\lib64
directory.
- Restart the HTTP server so the new configuration settings
take effect.