Re: pdo driver levels
| From: | Dan Scott | Date: | Tue, 03 Jan 2006 14:36:40 +0000 |
| Subject: | Re: pdo driver levels | ||
| References: | 1 2 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-3380@lists.php.net to get a copy of this message | ||
On 1/2/06, Curt Zirzow <czirzow@gmail.com> wrote:
> On Sun, Jan 01, 2006 at 04:28:06PM +0100, Lukas Smith wrote:
> > Hi,
> >
> > I think I have heard other people mention this before, but I would like
> > to bring this topic up again. It might be a good idea to define driver
> > "levels" that could help indicate how complete the given driver is.
> >
> > I do not have a real game plan yet, nor do I have a real overview where
> > drivers diverge at this point. However I presume we will get some more
> > features into PDO over time and so I presume the differences will become
> > bigger, especially for newer drivers.
> >
> > Possible points could be:
<snip>
> - rowCount() on selects, returns a value.
Augh -- this is *not* something related to the level of the PDO
driver. This is a database specific feature, and for some databases it
depends on which kind of cursor you have requested. So, for PDO_ODBC
for example, if you connect to a DB2 database and issue a SELECT
statement using a scrollable cursor, you will get a value from
rowCount(). However, you also incur locking and performance overhead
that aren't generally desirable.
As the docs for rowCount() say:
"""If the last SQL statement executed by the associated PDOStatement
was a SELECT statement, some databases may return the number of rows
returned by that statement. However, this behaviour is not guaranteed
for all databases and should not be relied on for portable
applications."""
As one of the comments to http://php.net/pdostatement-rowcount
suggests, for a portable method of counting rows, use fetchAll() if
you want to know how many rows your SELECT statement has returned. Or
if you just want to know whether you returned 0 rows, try fetching the
first one and checking the results of the fetch() call. Or if you just
need a rough number of rows that will be returned (say, for the
"Viewing 1-10 of 590,000 hits" status for a search), then issue the
SELECT COUNT(*) separately.
I believe it would be a mistake to label this as a "support level" of
the PDO drivers--this would be an artificial goal. Instead, I should
probably beef up the http://php.net/pdostatement-rowcount to better
cover the different scenarios in which you need to know the results of
the SELECT statement and provide portable suggestions for each
scenario.
Dan