且构网

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

php pdo连接到DB2不同的CODEPAGE

更新时间:2022-11-05 17:26:06

如果您专门为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.