php pdo连接到DB2不同的CODEPAGE [英] php pdo connected to DB2 different CODEPAGE

查看:97
本文介绍了php pdo连接到DB2不同的CODEPAGE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在连接到DB2 DB

I'm connecting to DB2 DB

$sql = 'CALL procedures.name(1,1,'text',1,1,'2017-08-30','2017-08-31',?,?)';
    try {
        $con = new PDO("idb:all_the_connections_stuu",'user','pass',
           [
              PDO::ATTR_PERSISTENT => FALSE,
              PDO::ATTR_ERRMODE => PDO:ERRMODE_EXCEPTION,
              PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL,
              PDO::ATTR_AUTOCOMMIT => 0
           ]
        );
        $stmt = $con->prepare($sql);
        $stmt->bindParam(1, $errorNumber, PDO::PARAM_INT);    //also trying without PDO::params  
        $stmt->bindParam(2, $errorCode, PDO::PARAM_STR, 800); //and with |PDO::PARAM_INPUT_OUTPUT
        $stmt->execute();        //return *TRUE*
        var_dump($errorNumber);  //return NULL
        var_dump($errorCode);    //return NULL
        var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); //returns Error
        $stmt->closeCursor();
        $stmt = null;
    } catch (PDOException $e) {
        echo ($e->getMessage());
    }

并收到此错误:

Fatal error:  Uncaught PDOException: SQLSTATE[57017]: <<Unknown error>>: -332 
[IBM][CLI Driver][DB2] SQL0332N  
Character conversion from the source code page "" to the target code page "" is not supported.  
SQLSTATE=57017
     (SQLFetchScroll[-332] at /home/user/shared/PDO_IBM-1.3.4/ibm_statement.c:1306) in /var/www/html/server/testsIBM/index.php:80
    Stack trace:
    #0 /var/www/html/server/testsIBM/index.php(80): PDOStatement->fetchAll(7, 0)
    #1 {main}
      thrown in /var/www/html/server/testsIBM/index.php on line 80

如果我与db2_connect连接

If I connect with db2_connect

$con = db2_connect("DATABASE=DB2D;HOSTNAME=10.243.13.65;PORT=5000;PROTOCOL=TCPIP;USERNAME=asdf23;PASSWORD=asdfasf1","", "")

并输出db2_client_info($con)db2_server_info($con)我看到来自客户端的 CONN_CODEPAGE = 819和来自服务器的 DB_CODEPAGE = 1208.

and output db2_client_info($con) and db2_server_info($con) I see that CONN_CODEPAGE from client = 819 and DB_CODEPAGE from server = 1208.

如何在客户端中设置 CONN_CODEPAGE ?我已经在CentOs语言环境中设置了LANG,但是仍然遇到字符转换错误.

How can I set CONN_CODEPAGE in my client? I already set LANG in CentOs locale, but still got error of character conversion.

______ upd:

______upd:

当前$ LANG = en_US.utf8(也在 locale -a 中,我有en_US,en_US.iso88591,en_US.iso885915,en_US.utf8)

Current $LANG = en_US.utf8 (also in locale -a I have en_US, en_US.iso88591, en_US.iso885915, en_US.utf8)

无论从 db2_client_info($ con)输出的$ LANG设置为什么,

No matter what $LANG is set output from db2_client_info($con) still the same:

 ["APPL_CODEPAGE"]=>
  int(819)
  ["CONN_CODEPAGE"]=>
  int(819)

与来自源代码页的字符转换

我正在使用PHP + Apache. Apache httpd.conf defaultCharset 设置了不同的语言环境并没有什么改变.

I'm using PHP+Apache. Apache httpd.conf defaultCharset setting different locales didnt't change anything.

在php代码 setlocale 中也不要更改任何内容.

In php code setlocale don't changing anything either.

我认为此设置存储在其他位置,并且 ibm_db2 pdo_ibm 驱动程序使用它. = |

I think this setting store somewhere else, and ibm_db2 or pdo_ibm drivers use it. =|

____ upd2

____upd2

我发现的唯一方法-从已安装的db2客户机更改DB2CODEPAGE.但是我还没有安装客户端.我正在使用Inly库.

The only way I found out - change DB2CODEPAGE from installed db2 client. But I don't have installed client. I'm using inly libraries.

现在我安装了v11.1.2fp2_linuxx64_client.tar.gz(1.03 GB).但是我不能启动db2客户端.认为我需要另一个新问题= \

Now i installed v11.1.2fp2_linuxx64_client.tar.gz (1.03 GB). But i can't laucn db2 client. Think I need another new question =\

____ upd3

____upd3

在使用CentO进行所有操作后,Apache语言环境-我仍然收到-322异常.不管我做了什么更改- db2_client_info($ con)仍然显示819 CodePage.一切都很好,直到fetch()/fetchAll()

After all manipulations with CentOs, apache locales - I still get -322 exception. No matter what I changed - db2_client_info($con) still shows me 819 CodePage. And all work nice, until fetch()/fetchAll()

已修补PDO_IBM 1.3.4的CentOs 7.3,PHP 7.1.8和ibm_db2. 我是从PECL来源制作此模块的(因为服务器没有Internet连接).

CentOs 7.3, PHP 7.1.8 with PDO_IBM 1.3.4-patched, and ibm_db2. BUT I make this modules from PECL sources (cause server doesn't have internet connection).

而且我也没有在我的应用程序服务器上安装任何DB2产品(这就是为什么我决定从CentOs语言环境获取CodePage的原因).从您的测试看来,DB2 data server client是必需的吗?

And I also don't have any DB2 products installed on mine application server (thats why I decide that CodePage getting from CentOs locale). It seems from your test, that DB2 data server client is required?

推荐答案

如果您专门为Centos客户端使用用于ODBC和CLI的IBM DB2数据服务器驱动程序",则可以尝试确保该帐户的环境运行PDO并连接到具有DB2CODEPAGE = 1208的DB2.您可以通过以下方式导出此变量(仅针对此特定的客户端类型):

If you are using the "IBM DB2 Data server driver for ODBC and CLI" specifically for your Centos client, you can try ensuring that the environment for the account that runs PDO and connects to DB2 has DB2CODEPAGE=1208. You can export this variable (only for this specific client type) via:

export DB2CODEPAGE=1208

,然后重新启动解决方案中涉及的任何过程.

and restart whatever process(es) are involved in your solution.

对于您用于连接到DB2的帐户,它们的客户端LANG设置也应该是UTF-8语言环境(并且该语言环境需要安装在Centos上).使用命令locale -a显示安装的语言环境,然后选择一个具有utf-8的语言环境.例如,如果您的$ LANG是en_us,则将其更改为en_us.utf-8(如果已安装该语言环境).在相关帐户的Shell启动中导出该$ LANG,然后重新启动您的应用.

Also for the account(s) you are using to connect to DB2, their client LANG setting should be an UTF-8 locale (and that locale needs to be installed on your Centos). Use the command locale -a to show which locales are installed, and choose one which has an utf-8 for your territory. For example if your $LANG was en_us then change it to en_us.utf-8, if that locale is installed. Export that $LANG in the shell startup of the relevant accounts and restart your apps.

如果使用完整的DB2客户端(或UNIX上DB2服务器上的本地DB2客户端),则还需要正确地将LANG变量设置为与DB2数据库的编码兼容的值.否则,您将在运行时获得代码页转换,这可能会产生意外结果,包括如果不存在合适的转换,则将导致异常.

If you are using a full-DB2 client (or the local DB2-client on a DB2-server on unix) you also need to correctly set the LANG variable to a value compatible with the encoding of your DB2 database. Otherwise you will either get codepage conversion at run time, which may have unexpected results, including exceptions if no suitable conversion exists.

有关信息:

在ubuntu 16.04 LTS上测试了具有PDO_IBM 1.3.4补丁的PHP 7.0.20,以及具有DB2 V11.1.2.2的ibm_db2-appl_codepage = conn_codepage = db_codepage.

Tested PHP 7.0.20 with PDO_IBM 1.3.4-patched, and ibm_db2 , with DB2 V11.1.2.2 , on ubuntu 16.04 LTS - appl_codepage = conn_codepage = db_codepage.

还在RHEL 6.9上测试了PDO_IBM 1.3.4修补程序的PHP 5.3.3和dbm_db2,以及DB2 V10.5.0.7:appl_codepage = conn_codepage = db_codepage.

Also tested PHP 5.3.3 with PDO_IBM 1.3.4-patched, and ibm_db2, with DB2 V10.5.0.7, on RHEL 6.9: appl_codepage = conn_codepage = db_codepage.

还在CENTOS 7.3上测试了PDO_IBM 1.3.4修补的PHP 5.4.16和ibm_db2,以及DB2 V11.1.2.2数据服务器客户端:appl_codepage = conn_codepage = db_codepage.

Also tested PHP 5.4.16 with PDO_IBM 1.3.4-patched and ibm_db2, with DB2 V11.1.2.2 data server client , on CENTOS 7.3: appl_codepage = conn_codepage = db_codepage.

注意:在从github构建pdo_ibm或使用pecl安装ibm_db2之前,Ubuntu,RHEL,Centos已为utf-8设置了默认语言环境.所有本地和远程数据库都具有utf-8编码.

Note: Ubuntu , RHEL, Centos had default locale set for utf-8, before building pdo_ibm from github, or installing ibm_db2 with pecl. All local and remote databases had utf-8 encoding.

这篇关于php pdo连接到DB2不同的CODEPAGE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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