This was done and tested on a Linux (CentOS) system running PHP 4.
- Configure PHP with ODBC support.
yum install php4-odbc unixODBC
You should check that it is successfully installed by doing phpinfo().
- Obtain the latest DB2 ODBC driver from IBM. You can download it from here. Lookout for Driver for ODBC and CLI.
- Untar it at a dir. I chose
/opt/db2cli. - Edit
odbcinst.inito define a new ODBC connection. The file should be located at/etc/odbcinst.ini. Add the following:[DB2] Description = DB2 Driver Driver = /opt/db2cli/lib/libdb2.so FileUsage = 1 DontDLClose = 1
- You can now connect to IBM DB2 on PHP via ODBC. You can use the following PHP script to test the connection:
$database = 'DBNAME'; $hostname = 'HOST'; $port = 'PORT'; $user = 'USERNAME'; $password = 'PASSWORD'; $driver = 'DB2'; $conn_string = "DRIVER=\{$driver};DATABASE=$database;HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;"; if (!$db = odbc_connect ($conn_string, $user, $password)) echo 'Error!'; else echo 'Success!'; odbc_close($db);
You can read about more information on PHP ODBC functions via PHP’s Manual.
Though this guide is based on PHP4, this should also work for PHP5 with some minor modifications. Otherwise, you can also check out DB2 extension of PHP.
uzyn.com is a weblog by U-Zyn Chua —A web developer and cloud computing consultant of
2 Comments
It’s been some time, and I’d like to understand about the bunch of ‘evil’ clowns at Ping.sg who always gave me trouble. Why do you condone such behavior??? You are at ransom, or you people are network-ed? I am just puzzled. LOL~ Rgds. If you have reply for this whch will help in my data compilation, pls drop it in my blog. (Outside notices) Thanks.
Hey. It’s been awhile. I still remember you. :) Actually I don’t know who or what you were referring to. We can talk further if you want. Email me or something.