pg_fetch_result

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

pg_fetch_resultReturns values from a result instance

Опис

pg_fetch_result(PgSql\Result $result, string|false|null $row, mixed $field): string|false|null
pg_fetch_result(PgSql\Result $result, mixed $field): string|false|null

pg_fetch_result() returns the value of a particular row and field (column) in an PgSql\Result instance.

Зауваження:

This function used to be called pg_result().

Параметри

result

Примірник PgSql\Result, якого повертає одна з функцій pg_query(), pg_query_params() або pg_execute() (серед інших).

row

Row number in result to fetch. Rows are numbered from 0 upwards. If omitted, next row is fetched.

field

A string representing the name of the field (column) to fetch, otherwise an int representing the field number to fetch. Fields are numbered from 0 upwards.

Значення, що повертаються

Boolean is returned as "t" or "f". All other types, including arrays are returned as strings formatted in the same default PostgreSQL manner that you would see in the psql program. Database NULL values are returned as null.

false is returned if row exceeds the number of rows in the set, or on any other error.

Журнал змін

Версія Опис
8.3.0 row is now nullable.
8.1.0 Тепер параметр result має бути примірником PgSql\Result. Раніше очікувався resource.

Приклади

Приклад #1 pg_fetch_result() example

<?php
$db
= pg_connect("dbname=users user=me");

$res = pg_query($db, "SELECT 1 UNION ALL SELECT 2");

$val = pg_fetch_result($res, 1, 0);

echo
"First field in the second row is: ", $val, "\n";
?>

Поданий вище приклад виведе:

First field in the second row is: 2

Прогляньте також