Thursday, June 5, 2014

PHP connect IBM db2 database in XAMPP



php_ibm_db2.dll is needed for PHP db2_connect function to connect to IBM db2 database.
1) Go to (for Windows)
http://sourceforge.net/projects/db2mc/files/IBM_DB2%20PHP%20Driver%20for%20Windows/
2) Click PHP 5.4._
Latest xampp is PHP5.5, but latest php_ibm_db2.dll is for PHP5.4
I have to install two version of XAMPP, one is PHP5.5, another PHP5.4 for php_ibm_db2.dll
3) Download
php_ibm_db2-1.9.5-5.4-ts-vc9-x86.zip
and unzip
4) Copy php_ibm_db2.dll to php/ext/ directory
5) In php.ini, add
extension=php_ibm_db2.dll
6)Restart Apache in XAMPP
7) My PHP test code to connect to IBM db2 database, replace to your database name, user name and password
<?php
//db2 express c  (v10.5) in local
$database = "SAMPLE";
$user = "db2admin";
$password = "admin123";

$conn = db2_connect($database, $user, $password);

if ($conn) {
echo "Connection succeeded.";
db2_close($conn);
}
else {
echo "Connection failed.";
}

?>
For Linux:
reference:
http://www.php.net/manual/en/ibm-db2.installation.php
Video: PHP connect IBM db2 database in XAMPP

1 comment:

  1. If the database server is not in the local, how can we connect?

    ReplyDelete