PDO相当于pg-result-seek

时间:2013-10-18 20:09:20

标签: php postgresql pdo

有人知道PDO相当于pg-result-seek吗?我想使用Postgre重绕数据集。

3 个答案:

答案 0 :(得分:1)

这是fetch功能的一部分: http://www.php.net/manual/en/pdostatement.fetch.php

但我认为没有必要这样做,如果选择行,你需要它(全部)......

答案 1 :(得分:1)

PDO的query()方法将返回PDOStatement Object。没有相应的东西像你要求的那样寻求特定的记录。一种替代方法可能是使用fetchAll()方法,然后获取您要查找的第N条记录。

<?php
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();

/* Fetch all of the remaining rows in the result set */
print("Fetch all of the remaining rows in the result set:\n");
$result = $sth->fetchAll();
print_r($result);

$ result [N]将包含您要查找的行。

答案 2 :(得分:1)

如果数据库允许,请使用PDO :: FETCH_ORI_ABS或PDO :: FETCH_ORI_REL,

例如

$result = $sth->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_ABS, 671);