Instalation of IBM DB2 module should be very easy (refering to the installation instructions):
- First of all, we need to download the driver package from here
- unpack the package to the server at /opt/ibm_db2/dsdriver
- chmod 755 installDSDriver
- ./installDSDriver
- Install pecl and php-pear (may need ksh): yum install php-pear
- pecl install ibm_db2
- When asked, provide the path to the db2 driver (here /opt/ibm_db2/dsdriver)
- You may check if it is installed by: pecl list
- Last thing: chmod o+w /opt/ibm_db2/dsdriver/cfg
- Edit /etc/php.ini and add extension=ibm_db2.so
- service httpd restart
Then in PHP:
<?php
$databaseName = "your_db_name";
$hostName = "your_host_name";
$port = 50001;
$userName = "your_user_name";
$password = "your_password";
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$databaseName;HOSTNAME=$hostName;PORT=$port;PROTOCOL=TCPIP;UID=$userName;PWD=$password;Security=ssl;";
$conn = db2_connect($conn_string, '', '');
if($conn) {
echo "Connected!";
db2_close($conn);
} else {
echo "Not connected<br>";
echo db2_conn_errormsg();
}
?>
Whole process with lot of pre-requisites for python is here (it works with little modifications for PHP too).