简体   繁体   中英

Php + ibm_db2 error

I'm having a problem with a PHP connection to a DB2 database. My systems specs are the following:

Operative System

[root@mxismspms POC]# uname -a Linux mxismspms.mx.ihost.com
2.6.18-419.el5 #1 SMP Wed Feb 22 22:40:57 EST 2017 x86_64 x86_64 x86_64 GNU/Linux

Php Version

php -v PHP 5.6.30 (cli) (built: Jan 19 2017 08:18:25)  Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

Php Loaded modules 
php -m [PHP Modules] 
bz2 calendar Core ctype curl date dom ereg exif fileinfo filter ftp gettext hash **ibm_db2** iconv json ldap libxml mhash mssql mysql mysqli mysqlnd odbc openssl pcntl pcre PDO pdo_dblib pdo_ibm pdo_mysql PDO_ODBC pdo_sqlite Phar posix readline Reflection session shmop SimpleXML sockets SPL standard sybase_ct sysvmsg sysvsem sysvshm tokenizer wddx xml xmlreader xmlwriter xsl zip zlib

As you can see i'm using ibm_db2 driver. The main issue is that connections to the DB2 database are not working when running from the Apache. My php script is the following:

$database = '****'; $user = '****'; $password = '****'; $hostname = '****'; $port = 5098;

$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .   "HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;"; $conn = db2_connect($conn_string, '', '');

if ($conn) {
    echo "Connection succeeded.";
    db2_close($conn); } else {
    echo "Connection failed.";
    print db2_conn_errormsg(); }

When in run it from the CLI it works fine, but it doesn't work when i run from the browser.

php test2.php 
Connection succeeded.

Also try with apache user.

su - apache -c 'php /var/www/html/POC/test2.php'        
Connection succeeded.

From browser I don't much details and it doesn't work. 参考1

Finally i give you my phpinfo driver and environment details. phpinfo 环境

And in my Yii 2 application i see this error.

SQLSTATE= , SQLDriverConnect: -5005 [IBM][CLI Driver] SQL10007N Message "0" could not be retrieved. Reason code: "3".

Regards!

用pecl重新安装ibm_db2可解决此问题(pecl安装ibm_db2)!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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