我最近开始使用 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());
}
任何帮助都会很好,谢谢
最佳答案
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));
}
关于php - 从 zend 调用 db2 存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10704829/