Search code examples
phpsqlasciiibm-midrangeebcdic

php - convert ebcdic to ascii


$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;

When this code block executes, $my_var has the value ¦–¦

The test RPGLE program being called is returning wow

When the program is altered, the characters i get back are different... so i know i'm getting back values from the program. The only issue is, how to convert these characters from EBCDIC to ASCII.


edit

I have tried using the following:

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

But i get this error: "Wrong charset, conversion from" ebcdic to ascii "is not allowed"

And, "Wrong charset, conversion from" cp037 to ascii "is not allowed"


Solution

  • On your CREATE PROCEDURE statement, use the CCSID that matches your language. For US English, that would be 37. Example:

    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