|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #56994 Additional functionality for PDOStatement object
Submitted: 2006-04-30 22:43 UTC Modified: 2006-05-01 10:56 UTC
From: ericanderson1999 at mac dot com Assigned:
Status: Not a bug Package: PDO (PECL)
PHP Version: 5.1.2 OS: RHEL, FC4, Mac OS X 10.4.6
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: ericanderson1999 at mac dot com
New email:
PHP Version: OS:


 [2006-04-30 22:43 UTC] ericanderson1999 at mac dot com
Here are a couple of feature requests:

1) Currently PDOStatement::fetch() and fetchAll() cannot be 
called more than once on the same instance. Initial calls 
appear to release the result set from the object. Subsequent 
calls return FALSE. You should be able to call fetch() and 
fetchAll() throughout the life of the instance.

2) PDOStatement should have a function or property that 
displays the number of rows returned by a select query. It 
is inconvenient to test for this by running count
(PDOStatement::fetchAll()) because this empties your result 
set from the PDOStatement instance.

3) A programmer should be able to move to a specific record 
in a result set and fetch it. For instance, 
PDOStatement::goTo(15) would set the pointer to record 
number 15, which could then be fetched. This would not 
release results 1-15 either. After jumping to record 15, it 
would be nice to jump back to record 1.

I think these additions would make PDO a much more 
attractive library. 

Thanks for all the work and time that has gone into this 
library so far.


Eric Anderson


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-01 00:05 UTC]
I think you're missing something fundamental.  You can do everything you've described already:

$results = $stmt->fetchAll();
echo "There were ", count($results), " rows".
$row15 = $results[14];
echo "There still are ", count($results), " rows".
$row1 = $results[0];
echo "There still are ", count($results), " rows".
 [2006-05-01 08:53 UTC]
Also don't forget that in many cases doing a count() query and a limited query with the results in a second go is much faster.
 [2006-05-01 10:56 UTC] ericanderson1999 at mac dot com
Thanks for the comments. Obviously, there are ways to do 
what I've suggested either by dumping results into an array 
outside of the results object, using multiple queries, or 
extending the PDO classes.

It just doesn't feel as neat and tidy as if this 
functionality were built in to the class.

At any rate, they're just suggestions for consideration.

Take care,

Eric Anderson
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Nov 29 08:01:23 2020 UTC