我终于明白了 SQL 存储过程和基于 RPG 或任何其他 AS400 对象的外部存储过程之间的区别。现在我尝试添加调用语句来执行外部存储过程,它只有一个 out 参数,由 RPG 程序生成,如下所示。
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 给了我代码,她说她用Surveyor/400 转换成外部存储过程。
角色扮演游戏:
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
测量员/400 的 DDL:
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
连接成功,$result 返回为“1”,但 $RTRNFLD 没有返回任何内容。
谢谢您的帮助,