If the second parameter is 0 or NULL (which eventually evaluates to 0) then the internal pointer is moved forward. < 0 value will return an warning.(PECL ibm_db2 >= 1.0.0)
db2_fetch_row — Modifica el puntero del conjunto de resultados a la siguiente línea o a la línea solicitada
Utilice db2_fetch_row() para iterar a través de un conjunto de resultados o para apuntar a una línea específica de un conjunto de resultados si se ha solicitado un cursor flotante.
Para obtener campos individuales del conjunto de resultados, llame a la función db2_result().
En lugar de llamar a las funciones db2_fetch_row() y db2_result(), la mayoría de las aplicaciones van a llamar a la función db2_fetch_assoc(), db2_fetch_both() o db2_fetch_array() para avanzar el puntero en el conjunto de resultados y devolver una línea completa como array.
stmt
Un recurso stmt válido que contiene el conjunto
de resultados.
row_numberCon cursores flotantes, puede solicitar un número de línea específico del conjunto de resultados. Los números de líneas comienzan con el índice 1
Devuelve true si la línea solicitada existe en el conjunto de resultados.
Devuelve false si la línea solicitada no existe en el conjunto de
resultados.
Ejemplo #1 Iterar a través de un conjunto de resultados
El siguiente ejemplo demuestra cómo iterar a través de un conjunto de resultados con la función db2_fetch_row() y recuperar las columnas del conjunto de resultados con db2_result().
<?php
$sql = 'SELECT nom, race FROM animales WHERE peso < ?';
$stmt = db2_prepare($conn, $sql);
db2_execute($stmt, array(10));
while (db2_fetch_row($stmt)) {
$nom = db2_result($stmt, 0);
$race = db2_result($stmt, 1);
print "$nom $race";
}
?>El ejemplo anterior mostrará:
gato Pook carpa dorada Bubbles periquito Gizmo cabra Rickety Ride
Ejemplo #2 Alternativas recomendadas i5/OS para db2_fetch_row/db2_result
En i5/OS, se recomienda que utilice
db2_fetch_both(), db2_fetch_array()
o db2_fetch_object() en lugar de
db2_fetch_row()/db2_result().
En general
db2_fetch_row()/db2_result() tiene más
problemas con tipos de columna variados en la traducción de
EBCDIC a ASCII, incluyendo posible
truncamiento en aplicaciones DBCS.
También podría encontrar una mejor performance utilizando
db2_fetch_both(), db2_fetch_array()
y db2_fetch_object() en lugar de
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);
?>El ejemplo anterior mostrará:
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
If the second parameter is 0 or NULL (which eventually evaluates to 0) then the internal pointer is moved forward. < 0 value will return an warning.if the second parameter (the row number) is specified, your connection needs to have the CURSOR option set to DB2_SCROLLABLE. Otherwise all calls to this function will fail. Internal to the ibm_db2 extension module the db2cli api function SQLFetchScroll() generates the error "CLI0145E Fetch type out of range" since it requires a scrollable resultset to work, instead of the default forward only resultset.
hope this saves someone the time it took me to track this down in the db2cli traces.
Regards,
Kris Dover