db2_fetch_row
db2_fetch_row
Sets the result set pointer to the next row or requested row
bool **db2_fetch_row** resource $stmt int $row_number
Use to iterate through a result set, or
to point to a specific row in a result set if you requested a scrollable
cursor.
db2_fetch_row
To retrieve individual fields from the result set, call the
function.
db2_result
Rather than calling and
, most applications will call one of
, ,
or to advance the result set pointer
and return a complete row as an array.
db2_fetch_row``db2_result``db2_fetch_assoc``db2_fetch_both``db2_fetch_array
stmt
A valid resource.
stmt
row_numberWith scrollable cursors, you can request a specific row number in the
result set. Row numbering is 1-indexed.
Returns true if the requested row exists in the result set. Returns false if the requested row does not exist in the result set.
Voorbeeld: Iterating through a result set
The following example demonstrates how to iterate through a result set
with and retrieve columns from the
result set with .
`db2_fetch_row``db2_result`
<?php
$sql = 'SELECT name, breed FROM animals WHERE weight < ?';
$stmt = db2_prepare($conn, $sql);
db2_execute($stmt, array(10));
while (db2_fetch_row($stmt)) {
$name = db2_result($stmt, 0);
$breed = db2_result($stmt, 1);
print "$name $breed";
}
?>
cat Pook
gold fish Bubbles
budgerigar Gizmo
goat Rickety Ride
Voorbeeld: i5/OS recommended alternatives to db2_fetch_row/db2_result
On i5/OS it is recommended that you use ,
, or
over /. In general
/ have more issues
with various column types in to
translation, including possible truncation in applications.
You may also find the performance of ,
, and to
be superior to /.
`db2_fetch_both``db2_fetch_array``db2_fetch_object``db2_fetch_row``db2_result``db2_fetch_row``db2_result``EBCIDIC``ASCII``DBCS``db2_fetch_both``db2_fetch_array``db2_fetch_object``db2_fetch_row``db2_result`
<?php
$conn = db2_connect("","","");
$sql = 'SELECT SPECIFIC_SCHEMA, SPECIFIC_NAME, ROUTINE_SCHEMA, ROUTINE_NAME, ROUTINE_TYPE, ROUTINE_CREATED, ROUTINE_BODY, IN_PARMS, OUT_PARMS, INOUT_PARMS, PARAMETER_STYLE, EXTERNAL_NAME, EXTERNAL_LANGUAGE FROM QSYS2.SYSROUTINES FETCH FIRST 2 ROWS ONLY';
$stmt = db2_exec($conn, $sql, array('cursor' => DB2_SCROLLABLE));
while ($row = db2_fetch_both($stmt)){
echo "<br>db2_fetch_both {$row['SPECIFIC_NAME']} {$row['ROUTINE_CREATED']} {$row[5]}";
}
$stmt = db2_exec($conn, $sql, array('cursor' => DB2_SCROLLABLE));
while ($row = db2_fetch_array($stmt)){
echo "<br>db2_fetch_array {$row[1]} {$row[5]}";
}
$stmt = db2_exec($conn, $sql, array('cursor' => DB2_SCROLLABLE));
while ($row = db2_fetch_object($stmt)){
echo "<br>db2_fetch_object {$row->SPECIFIC_NAME} {$row->ROUTINE_CREATED}";
}
db2_close($conn);
?>
db2_fetch_both MATCH_ANIMAL 2006-08-25-17.10.23.775000 2006-08-25-17.10.23.775000
db2_fetch_both MULTIRESULTS 2006-10-17-10.11.05.308000 2006-10-17-10.11.05.308000
db2_fetch_array MATCH_ANIMAL 2006-08-25-17.10.23.775000
db2_fetch_array MULTIRESULTS 2006-10-17-10.11.05.308000
db2_fetch_object MATCH_ANIMAL 2006-08-25-17.10.23.775000
db2_fetch_object MULTIRESULTS 2006-10-17-10.11.05.308000
db2_fetch_array``db2_fetch_assoc``db2_fetch_both``db2_fetch_object``db2_result