我最近开始使用db2的存储过程(一天前),我设法创建非常简单的SP,当我在iAccess Navigator中测试它们时工作正常。现在我试图从我的模型调用SP,但我得到错误,我不知道如何获得返回变量。这是一些代码
这是我的SP
drop procedure schema.test_ac ;
CREATE PROCEDURE schema.test_ac (IN a int, in b int, out c int)
LANGUAGE SQL
BEGIN
set c=b+a;
END;
这是php代码
public function storePro(){
$queryStr = "call test_ac (1,1,?)";
$stmt = $this->db->query($queryStr);
print_r($stmt->fetchAll());
}
任何帮助都会很好谢谢
答案 0 :(得分:2)
Zend_Db在处理DB2存储过程时可能会遇到问题。我会尝试在ZF 2.0中修复它。但是,今天您可以使用基本ibm_db2驱动程序函数成功运行示例。我在v7.1 IBM i系统上测试了这个:
// get actual db2 resource from ZF object
$dbConn = $this->db->getConnection();
if (!$dbConn) {
die("could not get connection");
}
$queryStr = "call test_ac (?, ?, ?)";
$stmt = db2_prepare($dbConn, $queryStr);
if (!$stmt) {
die ("Could not prepare statement. " . db2_stmt_error());
}
// set values to be bound. All three variables must be created.
$in1 = 1;
$in2 = 2;
$out1 = 0; // irrelevant but must provide
db2_bind_param($stmt, 1, "in1", DB2_PARAM_IN);
db2_bind_param($stmt, 2, "in2", DB2_PARAM_IN);
db2_bind_param($stmt, 3, "out1", DB2_PARAM_OUT);
$result = db2_execute($stmt);
if ($result) {
// success!
echo "value of output var: $out1";
} else {
die("Execute failed: " . db2_stmt_error($stmt));
}