3
votes

I am woking on a virtual machine operating CentOS 7, and I am trying to connect to an Informix database using ODBC (unixODBC) through some php.

I am using php7.0 and I have installed the unixODBC-2.3.7 as well as installed the informix sdk package (iif.12.10.FC12DE.linux-x86_64).

I have configures the odbc.ini and odbcinst.ini as such:

odbcinst.ini:

[ODBC Drivers]
IBM INFORMIX ODBC DRIVER=Installed
[IBM INFORMIX ODBC DRIVER]
Driver=/opt/IBM/Informix_Software_Bundle/lib/cli/iclis09b.so
Setup=/opt/IBM/Informix_Software_Bundle/lib/cli/iclis09b.so
APILevel=1
ConnectFunctions=YYY
DriverODBCVer=03.80
FileUsage=0
SQLLevel=1
smProcessPerConnect=Y

odbc.ini:

[ODBC Data Sources]
informix_db=IBM INFORMIXODBC DRIVER

[informix_db]
Driver=/opt/IBM/Informix_Software_Bundle/lib/cli/iclis09b.so
Description=IBM INFORMIX ODBC DRIVER
HostName=xxx.xxx.xxx.xxx
Service=xxxx
Database=xxx
LogonID=xxx
pwd=xxx
ServerName=xxx
Client_Locale=xxx
DB_Locale=xxx

I then set-up the environment variables with the following commands:

export INFORMIXDIR=/opt/IBM/Informix_Software_Bundle
export INFORMIXSERVER=xxx
export LD_LIBRARY_PATH=${INFORMIXDIR}/lib/cli

My php code is as follows:

<?php 
$dbUserName=xxx;
$dbPassword=xxx;
$conn=odbc_connect("Driver={IBM INFORMIX ODBC DRIVER};HOSTNAME=xxx;Database=xxx;PORT=xxx;PROTOCOL=onsoctcp;", $dbUserName, $dbPassword);
 if (!$conn)
 {
    echo odbc_errormsg();
 }
 else {
    $sql="{CALL somequery}";
    $res=odbc_exec($conn,$sql);
    odbc_result_all($res);
 }
?>

Unfortunately when I run the php I get the following error:

[unixODBC][Driver Manager]Can't open lib '/opt/IBM/Informix_Software_Bundle/lib/cli/iclis09b.so' : file not found

I have read on a similar question that this might be cause by the DriverVersion being wrong so I tried both 03.80 and 02.70 (the odbc installed with php and the unixODBC) inside odbcinst.ini.

I am fairly new to linux and can't tell what other problem might be causing it? Maybe I'm setting the environment variable false?

Thank you.

EDIT

Using the isql command worked after I tried the following: -Adding the following environment variables: INFORMIXSQLHOSTS CLIENT_LOCALE DB_LOCALE ODBCINI ONCONFIG -Adding the onconfig file and configuring it. -Adding the sqlhosts file and configuring it.

Still figuring out how to make the php code work (still giving the same error)

Hope that helps.

EDIT#2 Running the php through the terminal works and and I can successfully query the informix database with the previous database, it only does not work when I call the php code through the browser (using apache).

As suggested by someone on a different post, here is the results yielded by running ls -l in the directory where the driver libraries are located:

[root@administration-pc cli]# ls -l
total 21748
-rwxr-xr-x 3 informix informix 1865750 Jun 25  2018 iclis09b.so
-rwxrwxrwx 3 informix informix 1907069 Jun 25  2018 iclit09b.so
-rwxr-xr-x 2 informix informix   32805 Jun 25  2018 idmrs09a.so
-rw-r--r-- 2 informix informix 3595434 Jun 25  2018 libcli.a
-rw-r--r-- 2 informix informix   32864 Jun 25  2018 libdmr.a
-rw-r--r-- 2 informix informix 3595434 Jun 25  2018 libifcli.a
-rwxr-xr-x 3 informix informix 1865750 Jun 25  2018 libifcli.so
-rw-r--r-- 2 informix informix   32864 Jun 25  2018 libifdmr.a
-rwxr-xr-x 2 informix informix   32805 Jun 25  2018 libifdmr.so
-rwxr-xr-x 3 informix informix 1865750 Jun 25  2018 libixcli.so
-rwxrwxrwx 3 informix informix 1907069 Jun 25  2018 libtcli.so
-rw-r--r-- 1 informix informix 3593510 Jun 25  2018 libthcli.a
-rwxrwxrwx 3 informix informix 1907069 Jun 25  2018 libthcli.so
-rw-r--r-- 1 root     root           8 Mar 13 16:22 sample.txt

And here is result of phpinfo() for apache; and here the one for php running through the terminal.

I also ran exec('whoami') for both, and apache returns apache while the terminal returns root.

I tried changing the httpd.conf so that User is root instead of apache does let me start apache anymore.

Also changing the permissions of the iclis09b.so to apache does not seem to work.

EDIT#3(Solution)

Apache apparently does not have access to the environment variables, so you have to add all the environment variables to it...

Mine were located in /etc/sysconfig/httpd ...

1
you can try as informix user the isql tool included in the odbc manager: isql -v databasename to verify the configuration. May php is started with user with no access right to the informix dir.jacques
Need to include cli and esql in LD_LIBRARY_PATH. For example : LD_LIBRARY_PATH=/opt/ibm/informix/ids1210fc10/lib:/opt/ibm/informix/ids1210fc10/lib/esql:/opt/ibm/informix/ids1210fc10/lib/clijacques
@jacques yes I tried it, and it gives me the same error... but I did try to just read with php from the same directory where the library is and it did let me with a simple file_get_content; so Im assuming its not a permission problem? Im really bad with linux :/A.J Alhorr
and yes I did try including thecli and esql path...A.J Alhorr
@A.JAlhorr - You should not accept an answer that doesn't actually solve your problem. Better to write your own answer, that does solve your problem, and accept that. The short-form is that when running as a CGI (which mod_php does), you have to use setenv calls to set necessary environment variables either in your Apache httpd.conf or directly within your php scripts. (Note that comparing your php_info outputs shows LD_LIBRARY_PATH set for commandline php and not for apache with mod_php...)TallTed

1 Answers

5
votes

All the reference snippet you have mention is pointing to a direct usage of Informix ODBC driver, that is perfectly fine. I couldn't find any problem with the snippet that can lead to the error you are getting. At this moment I am bit puzzled about the error text snippet [unixODBC][Driver Manager]. I mean, the unixODBC Driver Manager should not come to picture when the application makes a direct reference to Informix ODBC driver. Can you please try LD_LIBRARY_PATH with the following value?

export LD_LIBRARY_PATH=${INFORMIXDIR}/lib:${INFORMIXDIR}/lib/esql:${INFORMIXDIR}/lib/cli

FYI: Since you have created a DSN (with the INI file), you could just specify the DSN name in the connection string used by the PHP application, for example:

"DSN=informix_db; uid=xxx; pwd=xxxx;"

In case if you would like to try troubleshoot with a pure ODBC sample application connection (I mean outside of PHP environment), then here is the ODBC application sample code. https://github.com/OpenInformix/ODBCExamples/blob/master/src/IfxOdbcSample1.c

https://github.com/OpenInformix/ODBCExamples/blob/master/src/odbc.ini

https://github.com/OpenInformix/ODBCExamples/blob/master/src/makefile

https://github.com/OpenInformix/ODBCExamples/blob/master/src/envc.bsh