Latest web development tutorials

PDOStatement :: nextRowset

PHP PDO Reference Manual PHP PDO Reference Manual

PDOStatement :: nextRowset - advance in a multi-line set in the statement handle to the next set of rows (PHP 5> = 5.1.0, PECL pdo> = 0.2.0)


Explanation

grammar

bool PDOStatement::nextRowset ( void )

Some databases support service returns more than one row set (also called a result set) stored procedures.

PDOStatement :: nextRowset () allows you to combine a PDOStatement object access the second and subsequent set of rows. Each row can have a different set of said set of columns.


return value

Successful return TRUE, or on failure returns FALSE.


Examples

Get set consists of a plurality of rows returned by a stored procedure

The following example shows how to call a stored procedure that returns three rows MULTIPLE_ROWSETS set. With a do / while loop to loop calling PDOStatement :: nextRowset () method returns false when no more rows set return and the end of the cycle.

<?php
$sql = 'CALL multiple_rowsets()';
$stmt = $conn->query($sql);
$i = 1;
do {
    $rowset = $stmt->fetchAll(PDO::FETCH_NUM);
    if ($rowset) {
        printResultSet($rowset, $i);
    }
    $i++;
} while ($stmt->nextRowset());

function printResultSet(&$rowset, $i) {
    print "Result set $i:\n";
    foreach ($rowset as $row) {
        foreach ($row as $col) {
            print $col . "\t";
        }
        print "\n";
    }
    print "\n";
}
?>

The above example output:

Result set 1:
apple    red
banana   yellow

Result set 2:
orange   orange    150
banana   yellow    175

Result set 3:
lime     green
apple    red
banana   yellow

PHP PDO Reference Manual PHP PDO Reference Manual