PHP Conference Japan 2024

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() 設定 result 實例中的內部列偏移量。

參數

result

pg_query()pg_query_params()pg_execute()(以及其他函式)所返回的 PgSql\Result 實例。

要將 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);

?>

參見

新增註釋

使用者貢獻的註釋 1 則註釋

andrew-php dot net at andrew dot net dot au
20 年前
啊,這是一個用於重置記錄索引的方便功能,例如,如果您使用 pg_fetch_{row,array,assoc} 迭代結果集,並且您想稍後再次執行此操作,而無需重新執行查詢。像這樣

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

將允許您再次迭代結果集...
To Top