无法通过linux计算机上的ODBC连接到notifyix [英] Cannot Connect to informix through ODBC on linux machine

查看:133
本文介绍了无法通过linux计算机上的ODBC连接到notifyix的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行CentOS 7的虚拟机上工作,我正尝试通过某些php使用ODBC(unixODBC)连接到Informix数据库.

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.

我正在使用php7.0,并且已经安装了unixODBC-2.3.7并安装了notifyix sdk软件包(iif.12.10.FC12DE.linux-x86_64).

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

我已经这样配置了odbc.ini和odbcinst.ini:

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

odbcinst.ini:

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

我的php代码如下:

<?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);
 }
?>

不幸的是,当我运行php时,出现以下错误:

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

我已经阅读了​​类似的问题这可能是由于DriverVersion错误导致的,所以我在odbcinst.ini中尝试了03.80和02.70(安装了php的odbc和unixODBC).

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.

我对linux还是很陌生,无法确定可能导致它的其他问题是什么?也许我将环境变量设置为false?

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?

谢谢.

编辑

在尝试以下操作之后,使用isql命令可以正常工作: -添加以下环境变量:INFORMIXSQLHOSTS CLIENT_LOCALE DB_LOCALE ODBCINI ONCONFIG -添加onconfig文件并对其进行配置. -添加sqlhosts文件并对其进行配置.

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.

仍在弄清楚如何使php代码正常工作(仍然给出相同的错误)

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

希望有帮助.

EDIT#2 通过终端运行php可以正常工作,并且我可以成功地使用以前的数据库查询notifyix数据库,只有当我通过浏览器(使用apache)调用php代码时,它才行不通.

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

此处是apache的phpinfo()的结果;和此处一个通过终端运行的php.

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

我也同时运行了exec('whoami')和apache返回apache而终端返回了root.

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

我尝试更改httpd.conf,以使Userroot而不是apache确实让我不再使用Apache.

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

iclis09b.so的权限更改为apache似乎也不起作用.

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

EDIT#3(解决方案)

Apache显然无权访问环境变量,因此您必须向其中添加所有环境变量...

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

我的矿井位于/etc/sysconfig/httpd ...

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

推荐答案

您提到的所有参考代码段都指向直接使用Informix ODBC驱动程序,这很好.我找不到该片段的任何问题,可能会导致您收到错误消息.目前,我对错误文本片段 [unixODBC] [Driver Manager] 感到困惑.我的意思是,当应用程序直接引用Informix ODBC驱动程序时,unixODBC驱动程序管理器不应出现.您可以使用以下值尝试 LD_LIBRARY_PATH 吗?

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

仅供参考:由于您已经创建了DSN(带有INI文件),因此可以在PHP应用程序使用的连接字符串中指定DSN名称,例如:

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;"

如果您想尝试使用纯ODBC示例应用程序连接进行故障排除(我的意思是在PHP环境之外),那么这里是ODBC应用程序示例代码. https://github.com/OpenInformix/ODBCExamples/blob/master/src /IfxOdbcSample1.c

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

这篇关于无法通过linux计算机上的ODBC连接到notifyix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆