PHP 8.4.1 Released!

pg_result_seek

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

pg_result_seek在 result 实例中设定内部行偏移量

说明

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

pg_result_seek()result 实例中设定内部行偏移量。

参数

result

PgSql\Result 实例,由 pg_query()pg_query_params() 或者 pg_execute()(等)返回。

row

PgSql\Result 实例中将内部偏移量移动到的行。行号从零开始。

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.1.0 现在 result 参数接受 PgSql\Result 实例,之前接受 resource

示例

示例 #1 pg_result_seek() 示例

<?php

// 连接到数据库
$conn = pg_pconnect("dbname=publisher");

// 执行查询
$result = pg_query($conn, "SELECT author, email FROM authors");

// 寻找第三行(假设有 3 行)
pg_result_seek($result, 2);

// 获取第三行记录
$row = pg_fetch_row($result);

?>

参见

添加备注

用户贡献的备注 1 note

up
5
andrew-php dot net at andrew dot net dot au
20 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