paginate()
The paginate()
method returns a paginated result set along with the total number of matching rows. It replaces the older get()
+ limit()
combination and ensures consistent pagination handling.
Signature:
public function paginate(string $table, int $page, array|string $columns = "*"): array
Basic Usage
$db->setPageLimit(2);
$page = 1;
$results = $db->paginate('products', $page);
$totalPages = $db->getTotalPages();
echo "Showing page $page of $totalPages";
Deprecated Notice:
The following properties are deprecated and should no longer be used:
The following properties are deprecated and should no longer be used:
$db->pageLimit
→ usesetPageLimit()
instead$db->totalPages
→ usegetTotalPages()
$db->arrayBuilder
→ usesetOutputMode('array')
Output Mode
You can control the result format using setOutputMode()
:
$db->setOutputMode('json');
$db->setPageLimit(5);
$results = $db->paginate('products', 1);
echo $results; // JSON string
Return Value
- Returns result set for the specified page
- Total number of pages via
getTotalPages()
- Total matching rows via
getTotalCount()
Notes
setPageLimit()
is required (default: 20)getTotalPages()
replaces deprecatedtotalPages
propertysetOutputMode()
replacesarrayBuilder()
- All conditions (
where()
,join()
, etc.) are supported