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
...
mod_php
does), you have to usesetenv
calls to set necessary environment variables either in your Apachehttpd.conf
or directly within your php scripts. (Note that comparing yourphp_info
outputs showsLD_LIBRARY_PATH
set for commandlinephp
and not forapache
withmod_php
...) – TallTed