Return result set and moves pointer to the first result.
bool/resource i5_next_result (resource Stmt)
Parameters
stmt |
i5_prepare returned request ID |
Return
Returns result set if OK, false if failed. Result set can be empty.
I5_ERR_PHP_HDLDFT |
256 |
No default connection found. |
I5_ERR_PHP_OPTIONSTYPE |
259 |
The type of " I5_OPTIONS_ALIAS" option must be x and not x |
I5_ERR_PHP_OPTIONSNUMBER |
260 |
Option number -1 is unknown. |
I5_ERR_PHP_TYPEPARAM |
262 |
Type of element x in parameter -1 must be y. Type z was provided. |
Details
i5_next_result function is used with prepared requests (or stored procedures) likely to return several results.
The next call to i5_fetch_xxx function with I5_READ_NEXT, will read next result of the result set, up to reach the end (End of file error returned).
If option I5_OPTIONS_AUTOMATIC_NEXT_RESULT wasn’t set to "1" during connection, you need to call i5_next_result() after i5_execute() call, to get the first result set.
Example
// CREATE PROCEDURE CR.CUSTSTMT2 (IN firstnameI CHAR(5))
// LANGUAGE SQL
// RESULT SETS 1
// BEGIN
//
// DECLARE stmt2 CURSOR FOR
// SELECT CUST_ID, LASTNAME
// FROM EASYCOMXMP.SP_CUST
// WHERE FIRSTNAME=firstnameI;
//
// -- Ouverture du curseur
// OPEN stmt2;
//
// RETURN;
//
// END;
//
// ////// Appel avec IBMi Access Client :
//
// call CR.CUSTSTMT2('Steve')
$req = i5_prepare('call CR/CUSTSTMT2(?)');
if ($req)
{
$firstname = 'Steve';
$ret = i5_setparam($req, 0, $firstname);
if (!$ret)
{
print_r("i5_setparam error : ".i5_errormsg().'<br/>');
}
/* Request execution */
$ret = i5_execute($req);
if (!$ret)
{
print_r("i5_execute error : ".i5_errormsg().'<br/>');
}
else
{
$stmt = i5_next_result($req);
if (is_bool($stmt) && $stmt == FALSE)
{
print_r("i5_next_result error : ".i5_errormsg().'<br/>');
}
else
{
$line = i5_fetch_row($stmt);
if($line === false)
{
print_r("i5_fetch_row error : ".i5_errormsg().'<br/>');
}
else
{
echo "First CUSTOMER : ";print_r($line);echo "<BR>";
}
while ($values = i5_fetch_row($stmt, I5_READ_NEXT ))
{
if(is_bool($values))
{
break;
}
echo "Next CUSTOMER : ";print_r($values);echo "<BR>";
}
if(is_bool($values))
{
if (i5_errno () == I5_ERR_BEOF)
{
echo "end of file<BR>";
}
else
{
print_r("i5_fetch_row error : ".i5_errormsg().'<br/>');
}
}
}
}
}
else
{
print_r("i5_prepare error : ".i5_errormsg().'<br/>');
}
See also