It's worth noting that this function consumes the value (the first call will return a result, and any subsequent calls will return NULL).
PHP - Manual: db2_result
2024-12-21
(PECL ibm_db2 >= 1.0.0)
db2_result — Returns a single column from a row in the result set
Use db2_result() to return the value of a specified column in the current row of a result set. You must call db2_fetch_row() before calling db2_result() to set the location of the result set pointer.
stmt
A valid stmt
resource.
column
Either an integer mapping to the 0-indexed field in the result set, or a string matching the name of the column.
Returns the value of the requested field if the field exists in the result set. Returns NULL if the field does not exist, and issues a warning.
示例 #1 A db2_result() example
The following example demonstrates how to iterate through a result set with db2_fetch_row() and retrieve columns from the result set with 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, 'BREED');
print "$name $breed";
}
?>
以上例程会输出:
cat Pook gold fish Bubbles budgerigar Gizmo goat Rickety Ride
It's worth noting that this function consumes the value (the first call will return a result, and any subsequent calls will return NULL).