0

I am installing a RHEL server with nginx and php that can connect to a db2 database, download and install the "IBM Data Server Client" package, also install the pecl library through:

pecl install ibm_db2

however when I do a connectivity test me responds with the following error:

[IBM] [CLI Driver] SQL10007N Message "0" could not be retrieved. Reason code: "3". SQLCODE = -1390

the code that I'm testing is:

<?php
$database = 'mydb';
$user = 'usr';
$password = 'pass';
$hostname = 'ipaddr';
$port = 9501;

$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" . "HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;";
$conn = db2_connect($conn_string, '', '');

if ($conn) {
    echo "Connection succeeded.";
    db2_close($conn);
}
else {
    echo db2_conn_error();
    echo db2_conn_errormsg();
}

am I missing something?

Edit:

searching in the web I found in phpe-ditors this:

If you created a DB2 instance named db2inst1 in /home/db2inst1/, for example, you can add the following line to php.ini:

ibm_db2.instance_name=db2inst1

If you do not set this option in php.ini, you must issue the following command to modify your environment variables to enable access to DB2:

bash$ source /home/db2inst1/sqllib/db2profile

To enable your PHP-enabled Web server to access these functions, you must either set the ibm_db2.instance_name configuration option in php.ini, or source the DB2 instance environment in your Web server start script (typically /etc/init.d/httpd or /etc/init.d/apache).

The problem is that I don't know whats the value for ibm_db2.instance_name

Any idea ?

  • Looks like the DB2 environment is not set up properly. Make sure you execute $INSTANCE_HOME/sqllib/db2profile script. – mustaccio Jul 16 '14 at 11:29
  • If you are looking for how to set up the DB2 environment, this was answered in another question: dba.stackexchange.com/questions/31336/adding-user-access-to-db2 – Chris Aldrich Jul 16 '14 at 12:49
  • @mustaccio: I do not understand what it means in my case $INSTANCE_HOME. since I only installed the client, not the server. In the installation process I do not create specific users for the database, the installation script indicated that the client is in "/opt/ibm/db2/V10.5/". Found in that directory and ran a script called "db2profile" in the subdirectory "cfg" but the error persists. Note that the installation was done with the root user. – PCJ Jul 16 '14 at 15:25
  • @Chirs Aldrich: the post that you refer is about install the database and I just want the client, that is because, is a web server that will host a php app that need database connection to an existing DB2 installation. – PCJ Jul 16 '14 at 15:29
  • 1) it would be better to create a client instance using the command db2icrt ( more details ) 2) make sure you source the profile: . /whatever/cfg/db2profile -- note the space after the . – mustaccio Jul 16 '14 at 15:37
0

With the help of @mustaccio achieved do as follows:

First I added the user db2inst1:     

db2inst1 useradd

Then, I generated the instance (whatever it means)              

/opt/ibm/db2/V10.5/instance/db2icrt db2inst1

Edit the php configuration file (/etc/php.ini) for add the instance:     

 extension = / usr/lib64/php/modules/ibm_db2.so 
 ibm_db2.instance_name = db2inst1

Edit the initialization file of the php-fpm service (/etc/init.d/php-fpm), which in my case is the one who runs php, to do the source of the db2profile script under the user running this service each time it starts.

 #for DB2
 . /opt/ibm/db2/V10.5/cfg/db2profile

And finally restart the service:

php-fpm restart service

Thank you very much for the comments.

0

Small correction with the answer of @PCJ in my case

Added the user

useradd db2inst1

Ran the below command

/opt/ibm/db2/V11.1/instance/db2icrt db2inst1

Edited php.ini and added below lines

extension=/usr/lib64/php/modules/ibm_db2.so
ibm_db2.instance_name=db2inst1

Then restarted the apache service

To test the connectivity, used "Example #2 Creating an uncataloged connection" in link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.