Tips for Db2 for Linux

 

Tip #1: How to setup the connection from PHP to Db2 for Linux

 

Target audience


Those who have difficulties to access Db2 from PHP.

Introduction


"Imagine" [The Beatles] ...

... you want to build a web page? With Apache's web server XAMPP and Db2? Well, then:

This tip explains the setups for both types of connection between PHP and Db2: PDO_IBM and ibm_db2.
The tip does not include the usage of these connection types.

Why this tip?

You might be in a similar situation as I was: I wasn't able to connect to Db2 for Linux.
For me at least, the offical documentation was too short. I needed help.

Acknowledgement


Finally, a friend of mine gave the essential hints:
Thank you so much, Günther Wagenzink (Berlin, Germany)!

The actual tip ...

.. consists of three files you can download:

How:
https://www.w3schools.com/TAGS/att_a_download.asp
https://www.w3schools.com/TAGS/tryit.asp?filename=tryhtml5_a_download
https://www.tutorialchip.com/php-download-file-script/

Tip #2: CRON / CRONTAB and Db2 for Linux

 

Target audience


Those who want to create their first CRON job accessing Db2 for Linux

Introduction


It's likely that you encounter the error
SQL10007N Message "-1390" could not be retrieved. Reason code: "3"
when trying to access Db2 from a CRON script for the first time.
How can you overcome this error?

The actual tip ...

a)
On the web, there are a lot of hints saying that the environment for the CRON job is not set up as you might asssume, e.g., for CRON, the PATH value is probably different from your userid's PATH value. Let's assume that you want to start "myscript.sh" every 30 minutes after the hour, your initial crontab entry looks like:
30 * * * * myscript.sh
If this script is not found [remember: PATH value], specify instead:
30 * * * * /full-path/myscript.sh
In my case, this produced the error message above. I tried the following: For Setting all the necessary environment variables as needed, I included "/home/db2inst1/sqllib/db2profile" into "myscript.sh". But this didn't solve the problem.

b)
Next hint on the web [https://community.spiceworks.com/topic/2363594-sql10007n-message-1390-could-not-be-retrieved-reason-code-3] states: "-1390" (in the error message above) is the SQL code, so issue: "db2 ? sql1390". This will tell you that DB2INSTANCE is not set properly. I therefore set DB2INSTANCE inside "myscript.sh" before connecting to the database, but I still got the same error message as before. So I enhanced my CRONTAB entry to:
30 * * * * DB2INSTANCE=db2inst1; /full-path/myscript.sh   [db2inst1 being the name of the instance]
This finaly worked. [Remark: I didn't check whether ATTACH inside "myscript.sh" would have solved the problem, too.]