2012-05-08 75 views
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的值爲| - |PHP - 轉換EBCDIC到ASCII

被稱爲是迴歸哇測試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「的轉換」

回答

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     
+0

當我們指定ccsid 37並嘗試調用SP ...我收到一條消息:artest中的程序lmtlib未找到指定的參數。 – adam

+1

參數需要完全匹配。我發佈的程序在您發佈的PHP代碼調用時工作。我在程序中使用了varchar,並在RPG中變化。 V5R4在這裏。 –

+0

所以如果我們做了CHARACTER(4),並且你做了VARCHAR(4),那會導致我看到的問題?我們的導演讓我訪問創建程序,以便我可以自己測試這個..然後我將能夠提供更好的反饋/響應:) – adam

1

我們e以下PHP函數:

$recoded = recode_string ('EBCDIC..ASCII', $my_var); 
+0

我沒有那個功能很遺憾。 「調用未定義的函數'recode_string'」 – adam

+0

PHP手冊說recode_string是PHP 4和PHP 5的一部分。 –

+0

我想如果你必須,你可以編寫自己的轉換函數。網絡上有EBCDIC和ASCII表格。 –

2

這是爲我們工作的幾個系統(IBM我v7r1,PHP版本5.4.16):

$ ascii_value =的iconv(「IBM- 1047「,」ISO8859-1「,$ ebcdic_value); // EBCDIC-> ASCII轉換

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; 

} 

?>