A pagination library which interacts with PDO
A set of classes which compliment and extend the PHP PDO library to provide support for pagination.
This is a beta release, and subject to change, however it is functional.
TODO: Investigate using
\PDO::ATTR_STATEMENT_CLASS in prepare method calls instead to reduce the complexity of the project.
composer.json file, then install
php composer.phar update
Create a pagination object to represent the current page
$pagination = new \CentralApps\Pagination\Pagination(); $pagination->setMaxResultsPerPage(25); $pagination->setCurrentPageNumber(1);
Instantiate the extended Pdo class
$pdo = new \CentralApps\Pagination\Pdo(...)
If you already have an extended Pdo class, the functionality is available within the PdoTrait class; though this is likely to change as functionality is migrated into the statement.
Call prepareWithPagination, passing the pagination object as the second parameter (driver options is available as the third parameter)
$statement = $pdo->prepareWithPagination($sql, $pagination);
The resulting statement is special. It contains within it, the statement for the paginated query, and a statement which counts the total number of applicable records (to calculate page numbers). Bindings to the statement apply to both statements, and upon execution, both statements are executed, the resulting page number stored within itself. Calling
getPaginationWithTotalCount on the statement post-execution returns the original pagination object, with total number of results. This can be used to generate a pagination nav-bar.