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 today

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

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

2152d ago

Major Versions

0.9 → 1.02020-08-11

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12673380?v=4)[Luan Maik](/maintainers/luanmaik)[@LuanMaik](https://github.com/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.8k287.3k1](/packages/wenzhixin-bootstrap-table)[babdev/pagerfanta-bundle

Bundle integrating Pagerfanta with Symfony

21019.3M93](/packages/babdev-pagerfanta-bundle)[webcreate/jquery-ias

Infinite Ajax Scroll: A jQuery plugin that turns your server-side pagination into an infinite scrolling one using AJAX

903736.3k3](/packages/webcreate-jquery-ias)[jasongrimes/paginator

A lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr. The 'first' and 'last' page links are shown inline as page numbers, and excess page numbers are replaced by ellipses.

4091.3M22](/packages/jasongrimes-paginator)[aplus/pagination

Aplus Framework Pagination Library

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

Infinite AJAX scrolling for Yii2 ListView widget

181732.8k10](/packages/kop-yii2-scroll-pager)

PHPackages © 2026

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