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 ?
Best Answer
With the help of @mustaccio achieved do as follows:
First I added the user db2inst1:
Then, I generated the instance (whatever it means)
Edit the php configuration file (/etc/php.ini) for add the instance:
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.
And finally restart the service:
Thank you very much for the comments.