php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #57623 PDO::FETCH_ORI_LAST & PDO::FETCH_ORI_PRIOR
Submitted: 2007-04-17 06:49 UTC Modified: 2016-09-12 22:14 UTC
Votes:5
Avg. Score:3.8 ± 0.7
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:0 (0.0%)
From: danil dot megrabjan at gmail dot com Assigned:
Status: Wont fix Package: PDO DBlib
PHP Version: 5.2.1 OS: sles 10
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-04-17 06:49 UTC] danil dot megrabjan at gmail dot com
Description:
------------
I have a mssql table. 
Something like this:

id | field1
-----------
1  | a
2  | b
3  | c
-----------

I want to move backward (from last to first), in my PDOStatment. But...

Reproduce code:
---------------
$db = new PDO('dblib:host=192.168.1.3:1433;dbname=db', 'user', 'password', array(PDO::ATTR_PERSISTENT => true));

$stmt = $db->prepare('select * from table', array(PDO::ATTR_CURSOR, PDO::CURSOR_SCROLL));
$stmt->execute();

$row = $stmt->fetch(PDO::FETCH_BOTH, PDO::FETCH_ORI_LAST);

while ($row = $stmt->fetch(PDO::FETCH_BOTH, PDO::FETCH_ORI_PRIOR)) {
  print $row[0] . "\t" . $row[1] . "\n";
}

$stmt = null;
?>

Expected result:
----------------
-------
3  | c
2  | b
1  | a
-------

Actual result:
--------------
-------
1  | a
2  | b
3  | c
-------

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-10 11:15 UTC] shol_ at hotmail dot com
I've a similar problem with PDO::FETCH_ORI_LAST as you have,
in my case I only want the last entry from the resultset, but 
PDO::FETCH_ORI_LAST fetches the first one.

If I fetch an x number of other entries with PDO::FETCH_ORI_PRIOR, after PDO::FETCH_ORI_LAST, then it spits out the same results as if I were doing an fetchAll().

Did you find an efficient workaround ?

I use  the same php version, but on ubuntu 9.1.

This is the only post on internet AFAIK, about this bug.
 [2013-06-12 01:51 UTC] ssufficool@php.net
-Package: PDO_DBLIB +Package: PDO related
 [2014-01-01 12:42 UTC] felipe@php.net
-Package: PDO related +Package: PDO DBlib
 [2014-10-25 04:33 UTC] ssufficool@php.net
-Assigned To: +Assigned To: ssufficool
 [2016-06-26 18:15 UTC] ssufficool@php.net
-Assigned To: ssufficool +Assigned To:
 [2016-09-12 22:14 UTC] adambaratz@php.net
-Status: Open +Status: Wont fix -Type: Bug +Type: Feature/Change Request
 [2016-09-12 22:14 UTC] adambaratz@php.net
pdo_dblib doesn't support scrollable cursors, so this would be a feature request. DB-Library doesn't exactly support them either. The closest thing it offers are row buffers. It might be possible to approximate this functionality with them, but the API semantics are a little different. For one thing, you have to declare a buffer size. Since use cases likely vary, it might be better to handle this at a higher level.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 03:01:29 2024 UTC