Accessing multiple DB2 instances using php->odbc_*

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
qwphil
Forum Newbie
Posts: 2
Joined: Tue Feb 28, 2006 9:58 am

Accessing multiple DB2 instances using php->odbc_*

Post by qwphil »

I am working with two DB2 instances on an AIX 5.2 machine, one of which has multiple local databases cataloged, and another one has local databases and also an AS/400 databases cataloged remotely through DB2 Connect.

I have compiled PHP to work with the DB2 Connect client and I have confirmed that I am able to connect to all of these databases through php, and even to multiple databases on the same DB2 instance (using PHP-CLI scripts). Here is the problem:

I am unable to connect to databases across the two DB2 instances within a single application run (e.g. using PHP-CGI with apache module). I can create two php programs one connecting to a db on one instance, and one connecting to a db in the other. However, I am unable to combine the run into one program, leading me to believe that db2 can "attach" one and only one instance to a process (I am currently using the putenv("DB2INSTANCE=$instance") technique). Googling, I could find nothing about how to re-attach instances, indeed I found that once attached it is apparently impossible to re-attach (see link below).

Here is the closest result google returned (after scrolling a while through multiple searches): http://dbforums.com/t366790.html which talks about switching contexts (gives c code)...

My ultimate question is: how do I access multiple DB2 instances in php? My main php environment is apache module (this is how my users use my deliverables). Is pcntl_fork an avenue? What about these context switches? Is there something trivial that I am missing?

Thank you all for this site, and in advance for your time,

phil
qwphil
Forum Newbie
Posts: 2
Joined: Tue Feb 28, 2006 9:58 am

Post by qwphil »

Well, I have made some progress with uncatalogued connections. My current problem is:

Warning: odbc_connect(): SQL error: [IBM][CLI Driver] SQLSTATE=58004, SQL state 58004 in SQLConnect
-or-
Warning: odbc_connect(): SQL error: [IBM][CLI Driver] SQL30082N Attempt to establish connection failed with security reason "24" ("USERNAME AND/OR PASSWORD INVALID"). SQLSTATE=08001 , SQL state 08001 in SQLConnect

I get those above errors intermittenly. The logins and passwords are fine (they are in the DSN string), and I get these errors wether I leave the login/pass blank, set to null, or set to actual login pass (regardless of what is in DSN):

odbc_connect('DRIVER={IBM DB2 ODBC DRIVER};DATABASE=prod;HOSTNAME=king12;PORT=50002;PROTOCOL=TCPIP;UID=db2lawp;PWD=pass'
,'','');
odbc_connect('DRIVER={IBM DB2 ODBC DRIVER};DATABASE=prod;HOSTNAME=king12;PORT=50002;PROTOCOL=TCPIP;UID=db2lawp;PWD=pass'
,null,null);
odbc_connect('DRIVER={IBM DB2 ODBC DRIVER};DATABASE=prod;HOSTNAME=king12;PORT=50002;PROTOCOL=TCPIP;UID=db2lawp;PWD=pass'
,'db2lawp','pass');

the above return the same two error messages, usually the first one (SQL error: [IBM][CLI Driver] SQLSTATE=58004, SQL state 58004) is returned when I do not have putenv("DB2INSTANCE=db2lawp") and the second one is returned if I do have that putenv; although this is not a rock hard rule, and sometimes it happens the other way around.

This is really weird, and really disheartening my experience with my favorite language (php) and what is touted as the rock solid database (db2) :(
jrd
Forum Commoner
Posts: 53
Joined: Tue Mar 14, 2006 1:30 am

Post by jrd »

Post Reply