Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

db2_num_rows(3) [php man page]

DB2_NUM_ROWS(3) 							 1							   DB2_NUM_ROWS(3)

db2_num_rows - Returns the number of rows affected by an SQL statement

SYNOPSIS
int db2_num_rows (resource $stmt) DESCRIPTION
Returns the number of rows deleted, inserted, or updated by an SQL statement. To determine the number of rows that will be returned by a SELECT statement, issue SELECT COUNT(*) with the same predicates as your intended SELECT statement and retrieve the value. If your application logic checks the number of rows returned by a SELECT statement and branches if the number of rows is 0, consider modi- fying your application to attempt to return the first row with one of db2_fetch_assoc(3), db2_fetch_both(3), db2_fetch_array(3), or db2_fetch_row(3), and branch if the fetch function returns FALSE. Note If you issue a SELECT statement using a scrollable cursor, db2_num_rows(3) returns the number of rows returned by the SELECT state- ment. However, the overhead associated with scrollable cursors significantly degrades the performance of your application, so if this is the only reason you are considering using scrollable cursors, you should use a forward-only cursor and either call SELECT COUNT(*) or rely on the boolean return value of the fetch functions to achieve the equivalent functionality with much better perfor- mance. PARAMETERS
o $stmt - A valid stmt resource containing a result set. RETURN VALUES
Returns the number of rows affected by the last SQL statement issued by the specified statement handle. PHP Documentation Group DB2_NUM_ROWS(3)

Check Out this Related Man Page

DB2_FETCH_BOTH(3)							 1							 DB2_FETCH_BOTH(3)

db2_fetch_both - Returns an array, indexed by both column name and position, representing a row in a result set

SYNOPSIS
array db2_fetch_both (resource $stmt, [int $row_number = -1]) DESCRIPTION
Returns an array, indexed by both column name and position, representing a row in a result set. Note that the row returned by db2_fetch_both(3) requires more memory than the single-indexed arrays returned by db2_fetch_assoc(3) or db2_fetch_array(3). PARAMETERS
o $stmt - A valid stmt resource containing a result set. o $row_number - Requests a specific 1-indexed row from the result set. Passing this parameter results in a PHP warning if the result set uses a forward-only cursor. RETURN VALUES
Returns an associative array with column values indexed by both the column name and 0-indexed column number. The array represents the next or requested row in the result set. Returns FALSE if there are no rows left in the result set, or if the row requested by $row_number does not exist in the result set. EXAMPLES
Example #1 Iterating through a forward-only cursor If you call db2_fetch_both(3) without a specific row number, it automatically retrieves the next row in the result set. The follow- ing example accesses columns in the returned array by both column name and by numeric index. <?php $sql = "SELECT id, name, breed, weight FROM animals ORDER BY breed"; $stmt = db2_prepare($conn, $sql); $result = db2_execute($stmt); while ($row = db2_fetch_both($stmt)) { printf ("%-5d %-16s %-32s %10s ", $row['ID'], $row[0], $row['BREED'], $row[3]); } ?> The above example will output: 0 Pook cat 3.20 5 Rickety Ride goat 9.70 2 Smarty horse 350.00 Example #2 Retrieving specific rows with db2_fetch_both(3) from a scrollable cursor If your result set uses a scrollable cursor, you can call db2_fetch_both(3) with a specific row number. The following example retrieves every other row in the result set, starting with the second row. <?php $sql = "SELECT id, name, breed, weight FROM animals ORDER BY breed"; $result = db2_exec($stmt, $sql, array('cursor' => DB2_SCROLLABLE)); $i=2; while ($row = db2_fetch_both($result, $i)) { printf ("%-5d %-16s %-32s %10s ", $row[0], $row['NAME'], $row[2], $row['WEIGHT']); $i = $i + 2; } ?> The above example will output: 0 Pook cat 3.20 5 Rickety Ride goat 9.70 2 Smarty horse 350.00 SEE ALSO
db2_fetch_array(3), db2_fetch_assoc(3), db2_fetch_object(3), db2_fetch_row(3), db2_result(3). PHP Documentation Group DB2_FETCH_BOTH(3)
Man Page