pg_result_seek

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

pg_result_seek結果リソースの内部行オフセットを設定する

説明

pg_result_seek(resource $result, int $offset): bool

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

パラメータ

result

pg_query(), pg_query_params() あるいは pg_execute() から返される PostgreSQL の クエリ結果リソース。

offset

結果リソース内で、内部オフセットを移動させる行。 行番号はゼロから始まります。

返り値

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

例1 pg_result_seek() の例

<?php

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

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

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

// 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