0
$my_var = "1";

$connection = db2_connect ( "*LOCAL", "ISCSC", "ISCSC" );

$strSql = 'CALL LMTLIB.ARTEST(?)';

$stmt = db2_prepare ( $connection, $strSql );

db2_bind_param($stmt, 1, "my_var", DB2_PARAM_INOUT, DB2_CHAR);

$rc = db2_execute ( $stmt );

echo $my_var;

当这个代码块执行时,$my_var 的值为 ¦–¦</p>

正在调用的测试 RPGLE 程序正在返回哇

当程序被改变时,我得到的字符是不同的......所以我知道我正在从程序中得到值。唯一的问题是,如何将这些字符从 EBCDIC 转换为 ASCII。


编辑

我尝试过使用以下内容:

mb_convert_encoding($my_var, "ASCII", "cp037");
mb_convert_encoding($my_var, "ASCII", "EBCDIC");
iconv("cp037", "ASCII", $my_var);
iconv("EBCDIC", "ASCII", $my_var);

但我收到此错误:“错误的字符集,不允许从”ebcdic 转换为 ascii“”

并且,“错误的字符集,不允许从”cp037 转换为 ascii“”

4

4 回答 4

2

这适用于我们的几个系统(IBM i v7r1,PHP 版本 5.4.16):

$ascii_value = iconv("IBM-1047","ISO8859-1", $ebcdic_value); // EBCDIC->ASCII 转换

于 2014-02-14T17:29:44.890 回答
1

使用以下 PHP 函数:

$recoded = recode_string ('EBCDIC..ASCII', $my_var);
于 2012-05-08T13:42:33.267 回答
1

在您的 CREATE PROCEDURE 语句中,使用与您的语言匹配的 CCSID。对于美国英语,这将是 37。示例:

CREATE PROCEDURE buck.phptest(         
 inout parm_inout varchar (5) ccsid 37)
LANGUAGE RPGLE                         
NOT DETERMINISTIC                      
CALLED ON NULL INPUT                   
EXTERNAL NAME buck.phptest             
PARAMETER STYLE GENERAL                
于 2012-05-08T15:46:23.527 回答
0

内置函数 EBCDIC 到 ASCII

我必须在窗口环境中这样做

 function ebcdic_to_ascii($ebcdic_hexstring /*expecting something like F0F1....*/)
    {
        //need to delcare it to avoid warning
$ebcd_ascii= null;
  // here come all the conversion
$ebcd_ascii["4A"] = "¢";
$ebcd_ascii["4B"] = ".";
$ebcd_ascii["4C"] = "<";
$ebcd_ascii["4D"] = "(";
$ebcd_ascii["4E"] = "+";
$ebcd_ascii["4F"] = "|";
$ebcd_ascii["5A"] = "!";
$ebcd_ascii["5B"] = "$";
$ebcd_ascii["5C"] = "*";
$ebcd_ascii["5D"] = ")";
$ebcd_ascii["5E"] = ";";
$ebcd_ascii["5F"] = "¬";
$ebcd_ascii["60"] = "-";
$ebcd_ascii["61"] = "/";
$ebcd_ascii["6A"] = "¦";
$ebcd_ascii["6B"] = ",";
$ebcd_ascii["6C"] = "%";
$ebcd_ascii["6D"] = "_";
$ebcd_ascii["6E"] = ">";
$ebcd_ascii["6F"] = "?";
$ebcd_ascii["79"] = "`";
$ebcd_ascii["7A"] = ":";
$ebcd_ascii["7B"] = "#";
$ebcd_ascii["7C"] = "@";
$ebcd_ascii["7D"] = "'";
$ebcd_ascii["7E"] = "=";
$ebcd_ascii["7F"] = " '' ";
$ebcd_ascii["81"] = "a";
$ebcd_ascii["82"] = "b";
$ebcd_ascii["83"] = "c";
$ebcd_ascii["84"] = "d";
$ebcd_ascii["85"] = "e";
$ebcd_ascii["86"] = "f";
$ebcd_ascii["87"] = "g";
$ebcd_ascii["88"] = "h";
$ebcd_ascii["89"] = "i";
$ebcd_ascii["91"] = "j";
$ebcd_ascii["92"] = "k";
$ebcd_ascii["93"] = "l";
$ebcd_ascii["94"] = "m";
$ebcd_ascii["95"] = "n";
$ebcd_ascii["96"] = "o";
$ebcd_ascii["97"] = "p";
$ebcd_ascii["98"] = "q";
$ebcd_ascii["99"] = "r";
$ebcd_ascii["A1"] = "~";
$ebcd_ascii["A2"] = "s";
$ebcd_ascii["A3"] = "t";
$ebcd_ascii["A4"] = "u";
$ebcd_ascii["A5"] = "v";
$ebcd_ascii["A6"] = "w";
$ebcd_ascii["A7"] = "x";
$ebcd_ascii["A8"] = "y";
$ebcd_ascii["A9"] = "z";
$ebcd_ascii["C0"] = "{";
$ebcd_ascii["C1"] = "A";
$ebcd_ascii["C2"] = "B";
$ebcd_ascii["C3"] = "C";
$ebcd_ascii["C4"] = "D";
$ebcd_ascii["C5"] = "E";
$ebcd_ascii["C6"] = "F";
$ebcd_ascii["C7"] = "G";
$ebcd_ascii["C7"] = "H";
$ebcd_ascii["C9"] = "I";
$ebcd_ascii["D0"] = "}";
$ebcd_ascii["D1"] = "J";
$ebcd_ascii["D2"] = "K";
$ebcd_ascii["D3"] = "L";
$ebcd_ascii["D4"] = "M";
$ebcd_ascii["D5"] = "N";
$ebcd_ascii["D6"] = "O";
$ebcd_ascii["D7"] = "P";
$ebcd_ascii["D8"] = "Q";
$ebcd_ascii["D9"] = "R";
$ebcd_ascii["E0"] = "\\";
$ebcd_ascii["E2"] = "S";
$ebcd_ascii["E3"] = "T";
$ebcd_ascii["E4"] = "U";
$ebcd_ascii["E5"] = "V";
$ebcd_ascii["E6"] = "W";
$ebcd_ascii["E7"] = "X";
$ebcd_ascii["E8"] = "Y";
$ebcd_ascii["E9"] = "Z";
$ebcd_ascii["F0"] = "0";
$ebcd_ascii["F1"] = "1";
$ebcd_ascii["F2"] = "2";
$ebcd_ascii["F3"] = "3";
$ebcd_ascii["F4"] = "4";
$ebcd_ascii["F5"] = "5";
$ebcd_ascii["F6"] = "6";
$ebcd_ascii["F7"] = "7";
$ebcd_ascii["F8"] = "8";
$ebcd_ascii["F9"] = "9";
$ebcd_ascii["FF"] = "E0";
    //end of conversion

    // loop until there is no more conversion.
    $asciiOut = "";    
    while(strlen($ebcdic_hexstring)>1)//F0F1F2F3F -> F1F2F3F
    {
        $thisEbcdic = substr($ebcdic_hexstring, 0, 2);//F0->F1
        //if(!is_null($ebcd_ascii[$thisEbcdic]))
        $asciiOut = $asciiOut.$ebcd_ascii[$thisEbcdic];//0->01
        $ebcdic_hexstring = substr($ebcdic_hexstring, 2);//F1F2F3F -> F2F3F
    }    

    return $asciiOut;

}

?>
于 2016-09-28T02:33:19.247 回答