PHPackages                             luanmaik/pdo-paginator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. luanmaik/pdo-paginator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

luanmaik/pdo-paginator
======================

This lib allow make easy pagination using PDO extension

1.0(5y ago)04MITPHPPHP ^7.1

Since Aug 7Pushed 5y ago1 watchersCompare

[ Source](https://github.com/LuanMaik/pdo-pagination)[ Packagist](https://packagist.org/packages/luanmaik/pdo-paginator)[ RSS](/packages/luanmaik-pdo-paginator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

PDOPaginator
============

[](#pdopaginator)

This library will help you to create pagination of records easily, using PDO.

[![php](https://camo.githubusercontent.com/d6fe7e1aec43af17285a3da10ae602401d22ee8e4774c20931a95a021a8efd4d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d372e312d677265656e6c69676874)](https://camo.githubusercontent.com/d6fe7e1aec43af17285a3da10ae602401d22ee8e4774c20931a95a021a8efd4d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d372e312d677265656e6c69676874)[![coverage](https://camo.githubusercontent.com/0c967d746eb7f4fe28065a3b94d23faa207cd6f4a968535b20fce0310a87cf89/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d677265656e)](https://camo.githubusercontent.com/0c967d746eb7f4fe28065a3b94d23faa207cd6f4a968535b20fce0310a87cf89/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d677265656e)[![php](https://camo.githubusercontent.com/97fdcc344e358f6a7ef10608cba88c7d79aedae98be76482c4d179784fab3c17/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f4c75616e4d61696b2f70646f2d706167696e6174696f6e)](https://camo.githubusercontent.com/97fdcc344e358f6a7ef10608cba88c7d79aedae98be76482c4d179784fab3c17/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f4c75616e4d61696b2f70646f2d706167696e6174696f6e)

Install using Composer
----------------------

[](#install-using-composer)

`composer require luanmaik/pdo-paginator`

Common Workaround
-----------------

[](#common-workaround)

**Using SQL\_CALC\_FOUND\_ROWS &amp; FOUND\_ROWS()**

```
# Search data
SELECT SQL_CALC_FOUND_ROWS * FROM user WHERE role = 'admin' LIMIT 10 OFFSET 5;
# Get number rows existents in previous query
SELECT FOUND_ROWS();
```

PROS: Simple

CONS: slow when use complex queries. *FOUND\_ROWS()* is deprecated.

---

**Using COUNT()**

```
# Search data
SELECT * FROM user WHERE role = 'admin' LIMIT 10 OFFSET 5;
# Get number rows existents
SELECT count(*) FROM user WHERE role = 'admin';
```

PROS: easy to read and efficiently.

CONS: Verbose.

How this libs works?
--------------------

[](#how-this-libs-works)

It uses the *count(\*)* pagination method (as above), but with a simple implementation, you set your query and the lib define the *limit* and *offset* instruction under the hood and running a second query using *count(\*)* to find the total number of registers available.

See the examples in below.

Simple usage example
--------------------

[](#simple-usage-example)

```
$paginator = new PDOPaginator\PDOPaginator($pdoConnection);
// Don't define the LIMIT instruction in your query
$paginator->query("SELECT * FROM users");
$paginationCollection = $paginator->execute($perPage = 15, $page = 1);

$paginationCollection->getTotal(); // Return total number of data in databse;
$paginationCollection->getData(); // Return array data;
$paginationCollection->getPerPage(); // 15 ... Return the number of registers per page
$paginationCollection->getPage(); // 1 ... Return the number page
$paginationCollection->getTotalPages(); // Return the total number of pages
$paginationCollection->getPaginationArray(); // Return the pagination details in array
```

Condition query params example
------------------------------

[](#condition-query-params-example)

Use `bindValue()` method.

```
$paginator = new PDOPaginator\PDOPaginator($pdoConnection);
$paginator->query("SELECT * FROM users WHERE role = :role");
$paginator->bindValue(':role', 'admin', PDO::PARAM_STR);
$paginationCollection = $paginator->execute($perPage = 15, $page = 1);
```

Custom fetch mode
-----------------

[](#custom-fetch-mode)

Use the third and fourth params in `execute()` method.

```
$paginator = new PDOPaginator\PDOPaginator($pdoConnection);
$paginator->query("SELECT * FROM users");
$paginationCollection = $paginator->execute($perPage = 15, $page = 1, PDO::FETCH_CLASS, User::class);

$paginationCollection->getData(); // returns User[]
```

Custom Collection
-----------------

[](#custom-collection)

Use the second param in `__construct()` method. The custom class MUST implements `\PDOPaginator\PDOPaginationCollectionInterface`.

```
// Create a custom collection
class MyCustomCollection extends \ArrayIterator implements \PDOPaginator\PDOPaginationCollectionInterface {
    //...
}
//OR you can extends the default collection implementation
class MyCustomCollection extends \PDOPaginator\PDOPaginationCollection {
    // overwrite some methods like toArray(), getPaginationArray(), etc.
}

$paginator = new PDOPaginator\PDOPaginator($pdoConnection, MyCustomCollection::class);
$paginator->query("SELECT * FROM users");
$paginationCollection = $paginator->execute($perPage = 15, $page = 1, PDO::FETCH_CLASS, User::class);
```

###  Health Score

22

—

LowBetter than 23% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

3

Last Release

2097d ago

Major Versions

0.9 → 1.02020-08-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/063ee5be32cc63fea59d329b26951a94964608eda3aa34525466a68a24a8f41b?d=identicon)[luanmaik](/maintainers/luanmaik)

---

Top Contributors

[![LuanMaik](https://avatars.githubusercontent.com/u/12673380?v=4)](https://github.com/LuanMaik "LuanMaik (10 commits)")

---

Tags

paginationpdophppdopagination

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/luanmaik-pdo-paginator/health.svg)

```
[![Health](https://phpackages.com/badges/luanmaik-pdo-paginator/health.svg)](https://phpackages.com/packages/luanmaik-pdo-paginator)
```

###  Alternatives

[wenzhixin/bootstrap-table

An extended table to integration with some of the most widely used CSS frameworks. (Supports Bootstrap, Semantic UI, Bulma, Material Design, Foundation)

11.8k283.4k1](/packages/wenzhixin-bootstrap-table)[babdev/pagerfanta-bundle

Bundle integrating Pagerfanta with Symfony

20817.8M65](/packages/babdev-pagerfanta-bundle)[aplus/pagination

Aplus Framework Pagination Library

2091.6M3](/packages/aplus-pagination)[kop/yii2-scroll-pager

Infinite AJAX scrolling for Yii2 ListView widget

180706.5k10](/packages/kop-yii2-scroll-pager)[coffeecode/paginator

Paginator is simple and is ready to generate results navigation in your application

59658.1k1](/packages/coffeecode-paginator)[beberlei/porpaginas

Library that generically solves several pagination issues with DAO/repository abstractions.

163612.6k11](/packages/beberlei-porpaginas)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
