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
18 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.
It’s truly a nice and useful piece of
info. I’m satisfied that you simply shared this helpful
information with us. Please keep us up to date like this.
Thanks for sharing.
Hi there, i read your blog occasionally and i own
a similar one and i was just
curious if you get a lot of spam comments? If so how do you reduce it, any
plugin or anything you can advise? I get so
much lately it’s driving me
insane so any support is very much appreciated.
you’re really a good webmaster. The website loading speed is amazing. It seems that
you are doing any unique trick. Furthermore, The contents are masterpiece. you have done a magnificent job on this topic!
Hi, Neat post. There is a problem with your web site in internet explorer, would check
this… IE still is the market leader and a huge portion of people will miss your
fantastic writing due to this problem.
Somebody essentially help to make severely articles I’d state. This is the first time I
frequented your website page and to this point? I surprised with the
research you made to create this particular publish
amazing. Magnificent task!
Oh my goodness! an incredible article dude.
Thank you Nevertheless
I’m experiencing challenge with ur rss . Don’t know why Unable
to subscribe to it. Is there anyone getting similar rss problem? Anybody who knows kindly respond. Thnkxxx
great post, very informative. I wonder why the
other experts of
this sector do not notice this. You should continue your writing.
I am sure, you have a great readers’ base already!
Wow that was unusual. I just wrote an incredibly long comment
but after I clicked
submit my comment didn’t show up. Grrrr… well I’m not writing all that over again.
Anyway, just wanted to say superb blog!
Great work! That is the type of information that are meant
to be shared across the web. Shame on Google for now not positioning this put up higher!
Come on
over and talk over with my website . Thanks
=)
Would you be eager about exchanging
hyperlinks?
Hi,
Do you have any example for Windows version?
Thank!!
I used to be suggested this web site by way of my cousin.
I am now not sure whether this post is written through him as no
one else know such particular approximately my problem. You’re amazing! Thank you!
Pretty portion of content. I just stumbled
upon your website and in accession capital to assert that
I get actually loved account your blog posts. Any way I’ll be subscribing
for your feeds or even I success you get
right of entry to persistently rapidly.
What’s up, its nice post about media print, we all know media is a fantastic source of information.
<a href=http://capitalplanners.net/controls/louisvuittonfactoryoutletcx.aspxlouis vuitton outlet online
A Lange Sohne is to watches what Mercedes is to cars. A Lange Sohne watches have drawn out been loved and admired. If you would like a good looking vigil that will fit your own particular mode of expression as well as make any equipment that you are wearing look even better, you want an A Lange Sohne wakefulness. These watches are just as popular and just as well loved as Rolex watches. The A Lange Sohne stripe offers a broad line of styles to prefer from, but the price file is quite limited and quite requiring great outlay. If you don’t have a large parcel for a new watchfulness, you may want to consider a Duplicate A Lange Sohne outlook.
3 Trackbacks
[...] the setup would be same/similar to Windows. I tried this in past and it worked .. Please check Connect to IBM DB2 on PHP via ODBC [...]
[...] Offers cheap, professional and fast PHP script installation service. Read More… [...]
[...] Take a look at my web-site – http://uzyn.com/how-to-connect-to-db2-on-php-via-odbc/ Source Page [...]