PHP, ODBC, DB2 in linux or macOS

Martin Roldan Araujo
2 min readAug 9, 2019

--

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!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Martin Roldan Araujo
Martin Roldan Araujo

Written by Martin Roldan Araujo

I write code 🤖 👾 🍳 🇲🇽 🏍

No responses yet

Write a response