gajus / gajus/doll

Implement "count" method

Open
#6 1 comment 0 reactions 1 assignee Claimed by @gajus View on GitHub
enhancement
Dominant language
PHP
Stars
34
Forks
7
PR merge metrics
No merged PRs in 30d

Description

This is useful when dealing with queries related to pagination where you want to retrieve data with a limit and offset, but also need to know the total number of records that match the query, e.g.

``` php
$sth = $db->prepare("SELECT `foo` FROM `bar` WHERE `baz` = 'qux' LIMIT 0, 10");
$sth->fetchAll();
```

The above gives up to 10 results and no indications of how many results there are in total that match the query.

It would be great to have a method `count`, which effectively is able to interpret the existing query, remove the "LIMIT" claus and give the number of total available records:

``` php
$sth->count();
```

This in effect would execute another query:

``` php
$sth = $db->prepare("SELECT COUNT(1) FROM `bar` WHERE `baz` = 'qux'");
```

The only drawback is that this would introduce SQL parser dependency.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.