简体   繁体   English

PHP 到 DB2 与 PDO_IBM 错误:SQLDriverConnect:-1390 [IBM] [CLIDRIVER] SQL10007N

[英]PHP to DB2 with PDO_IBM Error : SQLDriverConnect: -1390 [IBM] [CLIDRIVER] SQL10007N

In Ubuntu 22.04 I am attempting to connect PHP with a DB2 database via the driver pdo_ibm.so在 Ubuntu 22.04 我试图通过驱动程序 pdo_ibm.so 将 PHP 与 DB2 数据库连接起来

I have followed this guide, along with IBM documentation: https://github.com/php/pecl-database-pdo_ibm我遵循了本指南以及 IBM 文档: https://github.com/php/pecl-database-pdo_ibm

I've compiled version 1.5.0.我已经编译了 1.5.0 版本。 into the ".so" file and placed it on the respective driver's folder.进入“.so”文件并将其放置在相应驱动程序的文件夹中。

However I am getting the following error但是我收到以下错误

在此处输入图像描述

SQLDriverConnect: -1390 [IBM] [CLIDRIVER] SQL10007N Message "0" could not be retrieved. SQLDriverConnect:-1390 [IBM] [CLIDRIVER] SQL10007N 无法检索消息“0”。 Reason code "3".原因代码“3”。

Using the following PHP code:使用以下 PHP 代码:

var_dump($dsn);
echo "". PHP_EOL;
var_dump($this->_config['username']);
var_dump($this->_config['password']);
var_dump($this->_config['driver_options']);

$this->_connection = new PDO(
$dsn,
$this->_config['username'],
$this->_config['password'],
$this->_config['driver_options']
);

/*$this->_connection = new PDO("ibm:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=testdb;" .
"HOSTNAME=localhost;PORT=50000;PROTOCOL=TCPIP;", "db2inst1", "123456", array(
PDO::ATTR_PERSISTENT => FALSE, 
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
); */

I am using the follwing env variables, set on the ~/.bashrc file:我正在使用在 ~/.bashrc 文件中设置的以下环境变量:

ODBCHOME=/home/poc-dev/etc

ODBCINI=/home/poc-dev/clidriver/system_odbc.ini

DB2INSTANCE=db2inst1

DB2HOME=/home/poc-dev/clidriver

IBM_DB_HOME=/home/poc-dev/clidriver

LD_LIBRARY_PATH=/home/poc-dev/clidriver/lib

_=/usr/bin/printenv

I have succesfully connected with DBeaver and ISql to the database我已成功将 DBeaver 和 Isql 连接到数据库

What am I missing?我错过了什么?

Edit: The user running PHP is "www-data" image of apache envvars:编辑:运行 PHP 的用户是 apache envvars 的“www-data”图像: 在此处输入图像描述

Apache2 uses the "www-data" user to run PHP. As that "www-data" has to have full access to the DB2 CLIDRIVER in all senses as user mao pointed out. Apache2 使用“www-data”用户运行 PHP。正如用户 mao 指出的那样,“www-data”必须在所有意义上都具有对 DB2 CLIDRIVER 的完全访问权限。

I have found that I had to place the exact same variables as ~/.bashrc in the etc/enviroment file (I was mistakenly thinking I made them global), after I did that I could see the enviroment variables as the "www-data" user which I verified via the command:我发现我必须在 etc/enviroment 文件中放置与 ~/.bashrc 完全相同的变量(我错误地认为我将它们设为全局),在我这样做之后我可以看到环境变量作为“www-data “我通过命令验证的用户:

sudo -u www-data printenv

I confirmed the ENV-variables for the DB2 CLIDRIVER files folder: /home/poc-dev/clidriver were there, but they had 755 permissions which I needed to change to 777 permission via the command:我确认了 DB2 CLIDRIVER 文件夹的 ENV 变量:/home/poc-dev/clidriver 在那里,但它们有 755 权限,我需要通过命令将其更改为 777 权限:

sudo chmod 777 -R /home/poc-dev/ 

After that I tested the ISQL command on the user "www-data" by the command (since the first time I realized I was getting a message where ISQL could not find one of the libraries, which turned out to be a permissions problem):之后,我通过命令在用户“www-data”上测试了 ISQL 命令(因为我第一次意识到我收到一条消息,其中 ISQL 找不到其中一个库,结果证明是权限问题):

sudo -u www-data isql TEST db2inst1 123456

"TEST" being the registered DSN in odbc.ini, "db2inst1" being the user on the dataserver (in a virtual machine in this case) “TEST”是在 odbc.ini 中注册的 DSN,“db2inst1”是数据服务器上的用户(在本例中是虚拟机)

Then I proceded to use:然后我继续使用:

$this->_connection = new PDO("ibm:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=testdb;" .
"HOSTNAME=localhost;PORT=50000;PROTOCOL=TCPIP;", "db2inst1", "123456", array(
PDO::ATTR_PERSISTENT => FALSE, 
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
);

In PHP. Hopefully this helps someone在 PHP。希望这对某人有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM