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";

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 deprecated totalPages property
  • setOutputMode() replaces arrayBuilder()
  • All conditions (where(), join(), etc.) are supported

See Also