3

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 ...

A.J Alhorr
  • 527
  • 7
  • 27
  • 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 Mar 13 '19 at 16:05
  • 1
    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/cli – jacques Mar 13 '19 at 16:31
  • @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 Mar 14 '19 at 07:20
  • and yes I did try including thecli and esql path... – A.J Alhorr Mar 14 '19 at 07:21
  • I have noticed that once I added those path, the isql -v command now returns `[IM002][unixODBC][Informix][Informix ODBC Driver]Data source not found and no default driver specified.` `[ISQL]ERROR: Could not SQLConnect` even though both odbc.ini and odbcinst.ini are configured in the etc/ and unixODBC directories... do I have to configure one in the informix directory? – A.J Alhorr Mar 14 '19 at 07:43
  • 1
    @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 Mar 20 '19 at 14:09

1 Answers1

5

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

Satyan
  • 1,346
  • 8
  • 15
  • Hello, thank you for all your help, I have tried the LD_LIBRARY_PATH and it is not working :/ I just found out that I might have been using the wrong odbc.ini and odbcinst.ini; Im using the files located directly in the etc/ directory and not the ones inside the unixODBC folder, Im guessing they are the ones for the php ODBC? As for the DSN file, I did not quite understand, should I put the dsn uid and pwd inside the odbc.ini under the [informix_db]? I have tried to use the isql -v command from the terminal but it gives me the exact same error. I guess I will try to troubleshoot it – A.J Alhorr Mar 14 '19 at 07:11
  • using your ODBC sample application. Anyway, thank you a lot for your help – A.J Alhorr Mar 14 '19 at 07:11
  • 1
    You may specify uid and pwd inside the INI file, and it is only a matter of choice. If you specify all properties inside the INI file, then you just need to specify only the DSN name in the connection string. "DSN=informix_db". By any chance if you have specified a property both in INI and connection string then the property on the connection string will take precedence (and ignore the same property specified on the INI file.) – Satyan Mar 14 '19 at 15:38
  • 1
    @Satyan - The ODBC Driver Manager is always in the picture if the ODBC application is built with linkage to it, no matter whether the ODBC app uses a connect string that is DSN-less or DSN-full. This is actually a benefit of building a DBMS-agnostic ODBC-based app, because the Driver Manager can handle a number of translations (between ODBC versions, Unicode encodings, and other things), removing such responsibility from both app and driver. – TallTed Mar 20 '19 at 13:15
  • 1
    @A.JAlhorr - You may want to work with a single set of `odbc.ini` and `odbcinst.ini` files, typically in `/etc/`, with symlinks from any other current location. You can usually blend the content of multiple existing files. You can often also tell applications to use specific files (over-riding those at the default locations like `/etc/odbc.ini` or `~/.odbc.ini`) via the `$ODBCINI` and `$ODBCINSTINI` environment variables – TallTed Mar 20 '19 at 13:31