duanniu4106 2015-02-18 19:21
浏览 60
已采纳

如何从PHP调用IBM外部存储过程

I finally understand the differences between SQL Stored Procedure and External Stored Procedure which is based on RPG or any other AS400 objects. Now I tried to add the call statement to execute the External Stored Procedure which has only one out parameter and is generated by RPG program as below.

PHP:

$server="server";
$user="user";
$pass="pass";
$connect = db2_connect($server,$user,$pass); 
$RTVTYP = "D";
$RTRNFLD = "";
$strSql = 'CALL LIB.TEST_SP(?,?)';
$stmt = db2_prepare($connect, $strSql);

db2_bind_param($stmt, 1, "RTVTYP", DB2_PARAM_IN, DB2_CHAR);
db2_bind_param($stmt, 2, "RTRNFLD", DB2_PARAM_OUT, DB2_CHAR); 
$result = db2_execute($stmt);

print $result;
print $RTRNFLD;
db2_close($connect);

RPG Programmer gave me the code, and she said she used Surveyor/400 to convert into External Stored Procedure.

RPG:

d rpgprogram        pr                              
d rtvtyp_                             like(rtvtyp)
d rpgprogram        pi                              
d rtvtyp                         1                

/free                                                 
 exsr initial;                                        
 exsr process;                                        
 exec sql set result sets array :web_data for 1 rows; 
 return;                                              
 //***************************************************
 begsr process;                                       
 select;                                              
 when rtvtyp = 'D';                                   
    rtrnfld = 'Dog';                                  
 when rtvtyp = 'C';                                   
    rtrnfld = 'Cat';
 other;                   
    rtrnfld = 'Invalid';  
 endsl;                   
 endsr;                                                    
 begsr initial;                               
 w1size = %size(m2errds:*all);                
 p2err = %alloc(w1size);                      
 clear m2errds;                               
 endsr;                                       
/end-free                                     

DDL by Surveyor/400:

LIB.TEST_SP

General
Procedure: TEST_SP
Maximum number of result sets:1
Data access: MOdifies SQL data
Specific name: TEST_SP

Parameters
RTVTYP Character 1 IN
RTRNFLD Character 10 OUT
Parameter style:
Simple, no null values allowed

External Program
Program: rpgprogram
Schema: LIB
Language: RPGLE

Connection is successes, $result back as "1", but nothing $RTRNFLD returns.

Thank you for your help,

  • 写回答

2条回答 默认 最新

  • duanji1899 2015-02-18 21:28
    关注

    Without code to look at, it's very difficult to tell what may be the problem. Here is working code from my system.

    The PHP:

    $my_var = "1";                                                 
    $strSql = 'CALL BUCK.PHPTEST(?)';                              
    $stmt = db2_prepare ( $conn, $strSql );                        
    db2_bind_param($stmt, 1, "my_var", DB2_PARAM_INOUT, DB2_CHAR); 
    $result = db2_execute ( $stmt );                               
    

    The DDL:

    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                
    

    The RPGLE:

    d parm_inout      s              5a   varying         
    
    c     *entry        plist                             
    c                   parm                    parm_inout
    
    c/free                                                
      parm_inout  = 'Wow';                                
      *inlr = *on;                                        
      return;                                             
     /end-free                         
    

    When this runs in my test web page, $result is '1' and $my_var is 'Wow'. I am not calling the RPG program directly, I am calling the SQL External stored procedure which invokes the RPG program.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况