且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

php pdo 连接到 DB2 不同的 CODEPAGE

更新时间:2022-11-05 17:51:16

如果您使用的是专门为您的 Centos 客户端使用的IBM DB2 Data server driver for ODBC and CLI",您可以尝试确保该帐户的环境运行 PDO 并连接到 DB2 的 DB2CODEPAGE=1208.您可以通过以下方式导出此变量(仅针对此特定客户端类型):

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 和带有 DB2 V10.5.0.7 的 ibm_db2: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-patched 和 ibm_db2 的 PHP 5.4.16,带有 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.