Reputation: 95
I recently start playing with stored procedures for db2(one day ago) and I manage to create very simple SP that worked fine when I tested them in the iAccess Navigator. Now Im trying to call the SP from my model but Im getting errors back and Im not sure how to get the return variable. Here is some code
here is my 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;
here is the php code
public function storePro(){
$queryStr = "call test_ac (1,1,?)";
$stmt = $this->db->query($queryStr);
print_r($stmt->fetchAll());
}
any help will be nice Thank you
Upvotes: 2
Views: 1322
Reputation: 159
Zend_Db may have an issue when handling DB2 stored procedures. I'll try to get that fixed in ZF 2.0. However, today you can run your example successfully using the base ibm_db2 driver functions. I tested this on a v7.1 IBM i system:
// 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));
}
Upvotes: 2