PHP/SQL-将EBCDIC转换为ASCII [英] PHP / SQL - Convert EBCDIC to ASCII

查看:161
本文介绍了PHP/SQL-将EBCDIC转换为ASCII的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有PHP服务器代码,可以对我们的iSeries中型服务器执行SQL语句.

We have PHP server code, executing SQL statements against our iSeries midrange.

这是SQL查询的简化版本

Here is a simplified version of the SQL query

SELECT 'Regular' "sales_type", sum(sales_type1) "sales" FROM salesTable

查询执行得很好,问题在于使用静态字段/值(例如"SomeText"标题" )并且结果返回PHP时,它们不是所需的格式

The query executes just fine, the problem is that when using a static field/value such as 'SomeText' "Title" and the results come back in PHP, they are not in the desired format

string(7) "م�����" 

要连接到系统并检索结果

To connect to the system and retrieve the results

db2_connect ( '*LOCAL', 'user', 'pass' );
if (! $connection) {[error code]}
$stmt = db2_prepare ( $connection, $strSql );
if (! db2_execute ( $stmt ) ) { [error code ]
while ( $row = db2_fetch_array ( $stmt ) ) {
   var_dump($row[1]);
}

我们使用的是PHP 5.2.17版

We are on PHP version 5.2.17

我们的iSeries是V7R1M0

Our iSeries is V7R1M0

使用PHP或在SQL查询中转换服务器端自身的解决方案会很棒.

A solution to convert server side with PHP or in the SQL query its self would be great.

谢谢!

修改

出于雄鹿的建议,我们已将用户个人资料CCSID更改为37,而不是65535

From bucks suggestion we have changed the user profile CCSID to 37 instead of 65535

现在我们回到下面(靠近)...

Now we get back (below) which is a bit closer...

string(7) "Ù…‡¤"™"

这是否可能是因为我们仅更改了用户?是否也需要更改系统,作业或表?

Is this possibly because we only changed the user? Does the system, job or table need to be changed too?

编辑2

这是phpinfo的输出

Here is the phpinfo output

_COOKIE["ZDEDebuggerPresent"]   php,phtml,php3
_SERVER["ZendEnablerConfig"]    /www/zendserver/conf/fastcgi.conf
_SERVER["PHPRC"]    /usr/local/ZendSvr/etc/
_SERVER["PHP_FCGI_CHILDREN"]    40
_SERVER["PHP_FCGI_MAX_REQUESTS"]    0
_SERVER["CCSID"]    819
_SERVER["LANG"] C
_SERVER["INSTALLATION_UID"] 20101203131436121338
_SERVER["LDR_CNTRL"]    MAXDATA=0x40000000
_SERVER["LIBPATH"]  /usr/local/ZendSvr/lib
_SERVER["DB2NOEXITLIST"]    TRUE
_SERVER["ORACLE_HOME"]  .
_SERVER["ORA_NLS10"]    no value
_SERVER["ORA_NLS_PROFILE33"]    no value
_SERVER["FCGI_ROLE"]    RESPONDER
_SERVER["REDIRECT_UNIQUE_ID"]   UYKvWcCoAQIAAnZHWG8AABS@
_SERVER["REDIRECT_STATUS"]  200
_SERVER["UNIQUE_ID"]    UYKvWcCoAQIAAnZHWG8AABS@
_SERVER["QIBM_USE_DESCRIPTOR_STDIO"]    Y
_SERVER["HTTP_HOST"]    vmas400.vm.com:10090
_SERVER["HTTP_CONNECTION"]  keep-alive
_SERVER["HTTP_X_REQUESTED_WITH"]    XMLHttpRequest
_SERVER["HTTP_USER_AGENT"]  Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
_SERVER["CONTENT_TYPE"] application/x-www-form-urlencoded
_SERVER["HTTP_ACCEPT"]  */*
_SERVER["REFERER"]  http://vmas400.vm.com:10090ZendServer/Index/Index
_SERVER["HTTP_REFERER"] http://vmas400.vm.com:10090/ZendServer/Index/Index
_SERVER["REFERER_URL"]  http://vmas400.vm.com:10090/ZendServer/Index/Index
_SERVER["HTTP_ACCEPT_ENCODING"] gzip,deflate,sdch
_SERVER["HTTP_ACCEPT_LANGUAGE"] en-US,en;q=0.8
_SERVER["HTTP_ACCEPT_CHARSET"]  ISO-8859-1,utf-8;q=0.7,*;q=0.3
_SERVER["HTTP_COOKIE"]  ZENDSERVERSESSID=7asfv608qffhv556msem6evi66; CosmeticContest=16062; CompanyWithStoreDetail=16061; TYLYClassAnalysis=16068; OrderDetail=17220; RmsOrders=17221; DailyReceipts=16063; DailySales=17562; OnOrder=16064; OpenPurchaseOrders=17566; RegularPriceRankings=17568; ReviewStatistics=17570; SalesAndStock=17573; StocksByPeriod=17575; Top10BestSellers=17577; ReplenishmentAssortment=17269; RABS=17616; FreeFormatSku=16473; TYLYSalesAndOH=21294; SalesRecapByDate=16312; VendorAgendaSummary=23219; BasicStock=23474; InStock=16067; RegSalesAvgStockSummary=21270; TYLYSalesMDGMByStore=23822; VendorAgenda=23826; Header=16066; usc=adam; hudi[u]=d106b7a04c0d94b8a0e7624a017ead98324b57e8; hudi[i]=fec51923e58c84db4647d2b3e11fe03ec3f0c202; FreeFormat=16506; __utma=118969486.352613215.1355776933.1365626094.1367348033.12; __utmz=118969486.1355776933.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); ZDEDebuggerPresent=php,phtml,php3
_SERVER["PATH"] /bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin
_SERVER["SERVER_SIGNATURE"] no value
_SERVER["SERVER_SOFTWARE"]  Apache
_SERVER["SERVER_NAME"]  vmas400.vm.com
_SERVER["SERVER_ADDR"]  192.168.1.2
_SERVER["SERVER_PORT"]  80
_SERVER["REMOTE_ADDR"]  172.16.129.193
_SERVER["DOCUMENT_ROOT"]    /www/zendserver/htdocs/prod
_SERVER["SERVER_ADMIN"] [no address given]
_SERVER["SCRIPT_FILENAME"]  /usr/local/zendsvr/gui/html/index.php
_SERVER["DOCUMENT_NAME"]    /usr/local/zendsvr/gui/html/index.php
_SERVER["REMOTE_PORT"]  14259
_SERVER["REDIRECT_QUERY_STRING"]    dojo.preventCache=1367519066445
_SERVER["REDIRECT_URL"] /ZendServer/Information/Phpinfo
_SERVER["GATEWAY_INTERFACE"]    CGI/1.1
_SERVER["SERVER_PROTOCOL"]  HTTP/1.1
_SERVER["REQUEST_METHOD"]   GET
_SERVER["QUERY_STRING"] dojo.preventCache=1367519066445
_SERVER["REQUEST_URI"]  /ZendServer/Information/Phpinfo?dojo.preventCache=1367519066445
_SERVER["SCRIPT_NAME"]  /ZendServer/index.php
_SERVER["DOCUMENT_URI"] /ZendServer/index.php
_SERVER["RULE_FILE"]    conf/httpd.conf
_SERVER["PHP_SELF"] /ZendServer/index.php
_SERVER["REQUEST_TIME"] 1367519066


编辑

解决方案

解决方案是将用户配置文件更改为使用CCSID 37,将服务器作业更改为使用CCSID37.我们将进行手动更改,以便在作业重新启动时不会恢复.

The solution was to change the user profile to use CCSID 37, and the server jobs to use CCSID 37. We will make a manual change so that when the jobs are restarted, they do not revert.

推荐答案

如果IBM端配置正确,转换将自动发生.让IBM管理员检查系统值QCCSID.如果将其设置为65535,这就是为什么不进行翻译的原因. 65535说,系统上的所有数据都是二进制的,切勿转换. CCSID有一个层次结构.它以QCCSID从系统级别开始,向下移动到用户配置文件,最后向下移动到单个表.这是为了处理使用多种语言的系统.

The conversion can happen automatically if the IBM side is configured properly. Have the IBM admin check the system value QCCSID. If it's set to 65535, that's why no translation is taking place. 65535 says that all the data on the system is binary and should never be translated. There is a hierarchy of CCSIDs. It starts at the system level with QCCSID, moves down to the user profile and finally down to the individual table. This is to handle systems where multiple languages are in use.

系统处于65535的主要原因是因为当部署当前中端机器的远祖时,只有一种语言;一种EBCDIC,当引入多种语言时,默认语言设置为不翻译".

The main reason systems are at 65535 is because when the distant ancestor of the current midrange machines was deployed, there was a single language; one EBCDIC, and when multiple languages were introduced, the default language was set to 'do not translate'.

EBCDIC不再是单个字符集.每种语言都有一种编码.美国英语为CCSID(37).如果事实证明是CCSID,请让管理员使用正确的CCSID创建一个测试用户个人资料,然后尝试尝试.

EBCDIC is no longer a single character set. There is one encoding for each language. US English is CCSID(37). If it turns out that CCSID is the issue, have the admin create a test user profile with the proper CCSID and try that.

我刚刚在机器上进行了测试.

EDIT 1: I just did a test on my machine.

向返回的列中添加了文字.

EDIT 2: Added a literal to the returned columns.

<?php
  //Establish connection to database
  $host = "midrange";
  $conn = db2_connect ($host, user, pass);
?>

<table width="75%" border="1" cellspacing="1" cellpadding="1" bgcolor="#eeeeee">
<tr>
  <td><b>Name</b></td>
  <td><b>Email</b></td>
  <td><b>3rd column</b></td>
</tr>

<?php
$query = 'Select name, email, \'Markdown\' "THIRD" from table';

//Execute query
$queryexe = db2_exec($conn, $query) ;

//Fetch results
while(db2_fetch_row($queryexe)) {
 $name  = db2_result($queryexe, 'NAME');
 $email = db2_result($queryexe, 'EMAIL');
 $const = db2_result($queryexe, 'THIRD');

//Put the results in an HTML table.
print("<tr bgcolor=#ffffff>\n");
print("<td>$name</td>\n");
print("<td>$email</td>\n");
print("<td>$const</td>\n");
print("</tr>\n");
}
?>
</table>

我所有的表都是CCSID(37)IBM i 7.1.
phpinfo()报告IBM_DB2 1.9.0,PHP 5.3.3,我注意到我启用了iconv支持,并且我的服务器的CCSID是819-US ASCII.

All my tables are CCSID(37) IBM i 7.1.
phpinfo() reports IBM_DB2 1.9.0, PHP 5.3.3 I note that I have iconv support enabled and my server CCSID is 819 - US ASCII.

非常不完整的phpinfo()

Edit 3: very partial phpinfo()

ibm_db2
IBM DB2, Cloudscape and Apache Derby support    enabled
Module release  1.9.0
Module revision     $Revision: 297218 $
Binary data mode (ibm_db2.binmode)  DB2_BINARY
DB2 instance name (ibm_db2.instance_name)   no value

iconv
iconv support   enabled
iconv implementation    IBM iconv
iconv library version   unknown

Directive   Local Value Master Value
iconv.input_encoding    ISO8859-1   ISO8859-1
iconv.internal_encoding ISO8859-1   ISO8859-1
iconv.output_encoding   ISO8859-1   ISO8859-1
Environment
Variable    Value
ZendEnablerConfig   /www/zendsvr/conf/fastcgi.conf
PHPRC   /usr/local/ZendSvr/etc/
PHP_FCGI_CHILDREN   5
PHP_FCGI_MAX_REQUESTS   0
CCSID   819
LANG    en_US
INSTALLATION_UID    20101215125734236656
LIBPATH     /usr/local/ZendSvr/lib
DB2NOEXITLIST   TRUE

PHP Variables
Variable    Value
_REQUEST["TJE"] no value
_REQUEST["TE3"] no value
_REQUEST["ZDEDebuggerPresent"]  php,phtml,php3
_COOKIE["TJE"]  no value
_COOKIE["TE3"]  no value
_COOKIE["ZDEDebuggerPresent"]   php,phtml,php3
_SERVER["ZendEnablerConfig"]    /www/zendsvr/conf/fastcgi.conf
_SERVER["PHPRC"]    /usr/local/ZendSvr/etc/
_SERVER["PHP_FCGI_CHILDREN"]    5
_SERVER["PHP_FCGI_MAX_REQUESTS"]    0
_SERVER["CCSID"]    819
_SERVER["LANG"] en_US
_SERVER["INSTALLATION_UID"] 20101215125734236656
_SERVER["LIBPATH"]  /usr/local/ZendSvr/lib
_SERVER["DB2NOEXITLIST"]    TRUE
_SERVER["FCGI_ROLE"]    RESPONDER
_SERVER["SCRIPT_URL"]   /hello.php
_SERVER["QIBM_USE_DESCRIPTOR_STDIO"]    Y
_SERVER["HTTP_USER_AGENT"]  Mozilla/5.0 (Windows NT 6.1; rv:20.0) Gecko/20100101 Firefox/20.0
_SERVER["HTTP_ACCEPT"]  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
_SERVER["HTTP_ACCEPT_LANGUAGE"] en-US,en;q=0.5
_SERVER["HTTP_ACCEPT_ENCODING"] gzip, deflate
_SERVER["HTTP_DNT"] 1
_SERVER["HTTP_CONNECTION"]  keep-alive
_SERVER["HTTP_PRAGMA"]  no-cache
_SERVER["HTTP_CACHE_CONTROL"]   no-cache
_SERVER["PATH"] /bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin
_SERVER["SERVER_SIGNATURE"] no value
_SERVER["SERVER_SOFTWARE"]  Apache
_SERVER["DOCUMENT_ROOT"]    /www/zendsvr/htdocs
_SERVER["SERVER_ADMIN"] [no address given]
_SERVER["SCRIPT_FILENAME"]  /www/zendsvr/htdocs/hello.php
_SERVER["DOCUMENT_NAME"]    /www/zendsvr/htdocs/hello.php
_SERVER["REMOTE_PORT"]  54747
_SERVER["GATEWAY_INTERFACE"]    CGI/1.1
_SERVER["SERVER_PROTOCOL"]  HTTP/1.1
_SERVER["REQUEST_METHOD"]   GET
_SERVER["QUERY_STRING"] no value
_SERVER["REQUEST_URI"]  /hello.php
_SERVER["SCRIPT_NAME"]  /hello.php
_SERVER["DOCUMENT_URI"] /hello.php
_SERVER["RULE_FILE"]    conf/httpd.conf
_SERVER["PHP_SELF"] /hello.php
_SERVER["REQUEST_TIME"] 1367514482

如何进行服务器作业CCSID(37)

Edit 4: How to make server jobs CCSID(37)

有几种方法可以使服务器作业运行美国英语.这是管理员决定哪个对整体服务器操作影响最小的决定.我将我的仅限美国英语的系统设置为通过IPL转到QCCSID 37,没有发现任何问题.

There are several ways to get the server jobs to run US English. It's an admin decision as to which is lowest impact on the overall server operation. I set my US English-only system to go to QCCSID 37 over a IPL and have seen no issues.

  1. CHGSYSVAL QCCSID 37-这会将整个服务器设置为美国英语.重新启动Apache服务器以使其生效.
  2. CHGUSRPRF QTMHHTTP CCSID(37)-这会将所有HTTP服务器作业设置为美国英语.重新启动Apache服务器以使其生效.
  3. 重新配置Apache服务器.设置CgiConvMode EBCDICDefaultNetCCSID 819CGIJobCCSID 37重新启动Apache服务器以使其生效.请参见 CGI数据转换有关详细信息.这会将一台Apache服务器的作业设置为美国英语.
  4. CHGPF ... CCSID(37)-这会将文件设置为美国英语.需要全部更改.
  1. CHGSYSVAL QCCSID 37 - This will set the entire server to US English. Restart the Apache server to take effect.
  2. CHGUSRPRF QTMHHTTP CCSID(37) - This will set all of the HTTP server jobs to US English. Restart the Apache server to take effect.
  3. Reconfigure the Apache server. Set CgiConvMode EBCDIC and DefaultNetCCSID 819 and CGIJobCCSID 37 Restart the Apache server to take effect. See CGI Data Conversions for the details. This will set one Apache server's jobs to US English.
  4. CHGPF ... CCSID(37) - This will set the file to US English. Need to alter them all.

这并不旨在包括所有内容.更像是层次结构如何融合在一起的总结.

This isn't intended to be all inclusive. More like a rundown of how the hierarchy fits together.

这篇关于PHP/SQL-将EBCDIC转换为ASCII的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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