Skip to content

Commit

Permalink
Fix pagination in query()
Browse files Browse the repository at this point in the history
  • Loading branch information
ronanchilvers committed Jun 12, 2019
1 parent 44ae164 commit a1c4d95
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ public function query($sql, $params = [], $page = null, $perPage = 20)
{
if (!is_null($page)) {
$page = (int) $page;
if ($page < 0) {
$page = 0;
if ($page < 1) {
$page = 1;
}
$offset = $perPage * $page;
$offset = $perPage * ($page - 1);
$limit = $perPage;

$sql .= " LIMIT {$limit} OFFSET {$offset}";
Expand Down Expand Up @@ -229,7 +229,6 @@ protected function generateCallback()
implode(' : ', $stmt->errorInfo())
);
}

if ('select' !== strtolower(substr($sql, 0, 6))) {
return $result;
}
Expand Down

0 comments on commit a1c4d95

Please sign in to comment.