php.net |  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
24 - 8 = ?
Subscribe to this entry?

 
 [2006-04-30 22:43 UTC] ericanderson1999 at mac dot com
Description:
------------
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.

Best,

Eric Anderson


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-01 00:05 UTC] wez@php.net
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];
var_dump($row15);
echo "There still are ", count($results), " rows".
$row1 = $results[0];
var_dump($row1);
echo "There still are ", count($results), " rows".
 [2006-05-01 08:53 UTC] helly@php.net
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: Thu Dec 03 20:01:23 2020 UTC