pg_result_seek

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

pg_result_seek結果インスタンスの内部行オフセットを設定する

説明

pg_result_seek(PgSql\Result $result, int $row): bool

pg_result_seek()は、結果インスタンスの行の位置を 指定された offset にセットします。

パラメータ

result

pg_query()pg_query_params() や (様々な関数がありますが、特に) pg_execute() が返した PgSql\Result クラスのインスタンス。

row

PgSql\Result クラスのインスタンス内で、内部オフセットを移動させる行。 行番号はゼロから始まります。

戻り値

成功した場合に true を、失敗した場合に false を返します。

変更履歴

バージョン 説明
8.1.0 result は、PgSql\Result クラスのインスタンスを期待するようになりました。 これより前のバージョンでは、リソース を期待していました。

例1 pg_result_seek() の例

<?php

// データベースに接続する
$conn = pg_pconnect("dbname=publisher");

// クエリを実行する
$result = pg_query($conn, "SELECT author, email FROM authors");

// 3 行目をシークする(結果が 3 行あると仮定する)
pg_result_seek($result, 2);

// 3 行目を取得する
$row = pg_fetch_row($result);

?>

参考

add a note add a note

User Contributed Notes 1 note

up
4
andrew-php dot net at andrew dot net dot au
19 years ago
Ah, this is a handy feature for resetting the record index, for example, if you're used pg_fetch_{row,array,assoc} to iterate over the result set, and you want to do it again later on, without reexecuting your query. Something like:

<?php pg_result_seek($result, 0); ?>

will allow you to iterate over the result set all over again...
To Top