Repository navigation
limit
Applies a limit and an optional offset to a SELECT, UPDATE, or DELETE query. This method restricts the number of rows affected or returned by the statement.
📌 This method is ideal for implementing data pagination. By dynamically calculating the
$offsetbased on the current page number, you can easily slice your database results into manageable chunks. You can also handle offsets separately using the offset method.
limit(int $limit = 0, int $offset = 0): static
limit (integer) : The maximum number of rows to return or affect. Must be a positive integer.
offset (interger)
: The number of rows to skip before starting to return rows. (Only applicable to SELECT statements.) ^(optional)^
If the offset number is a negative number than it will be ignored.
(static) : Returns the current instance to allow for method chaining.
$db->select()->limit(10)->execute();
// Result: SELECT * FROM `table` LIMIT 10
$db->select()->limit(10, 20)->execute();
// Result: SELECT * FROM `table` LIMIT 10 OFFSET 20
- Logs a notice if limit is not a positive integer.
- Triggers a warning if trying to use
OFFSETon anUPDATEorDELETEstatement. - Throws an exception if
limit()is used without an explicitorder()clause.