Codementor Events

PHP, ODBC, DB2 in linux or macOS

Published May 26, 2020Last updated Apr 14, 2021

This is taken from my most read post in Medium.

A scary tale where docker saves the day
TL;DR you may want to use this docker image https://cloud.docker.com/u/mkphp/repository/docker/mkphp/php-ibm-odbc
How do you connect PHP to a Database?

Well, you use the right driver, right? Which is usually ready for you to use out-of-the-box or at least, you just download it, enable it and that’s it.
For DB2 it’s bit more complicated than that.
First of all, I’m not saying DB2 is bad as a RDBMS. It has nice features and is robust. BUT…

DB2 is a proprietary piece of burocratic software from IBM. It’s ancient. It’s tightly coupled with the operating system from IBM (AFAIK).
By being deeply tied to the OS, it means you can’t just install DB2 in your Linux (ubuntu, fedora, centOS, etc), MacOS or Windows machine (just like MariaDB, MySQL, etc).

Now, that’s a problem.

A: What if I want to grab a copy from the database and have it locally to mess it up locally without risking stuff from staging or develop?
B: You can’t do that. At least not easily. There’s a way using containers but that’s a story for another day.
A: Well, I could connect remotely, right?
B: Yeah, assuming we have the right license for it.
A: Wait, are you telling me I need a special license just to connect to the database from a client? that’s crazy.
A: Okay, I’ll just set the DSN on my PDO on PHP to point to the development server
B: Sure. You’re using windows, right?
A: Ugh, hell no. I’m using linux, baby.
B: Oh, then you have to download the DSDriver from IBM’s website. Extract it. Install it. Copy the files to a safe location like /opt/ibm/dsdriver. Don’t forget to copy the .lic file too; our sysadmin will send you that one.
B: Once you have done that, THEN you can install the ibm_db2 driver for pdo through PECL.It’ll prompt for the dsdrivler/clidriver location.
B: Don’t forget to enable extension=ibm_db2.so in you php.ini
A: …okay.
B: OR if you’re using docker, use this image and just mount the license over.
A: nice!

Discover and read more posts from Martin Roldan
get started
post commentsBe the first to share your opinion
Sumith
4 years ago

vendor/autoload.php file missing after download it from github

Show more replies