From a1c4d958a48a5162648188e7d0fb98085abfe997 Mon Sep 17 00:00:00 2001 From: Ronan Chilvers Date: Wed, 12 Jun 2019 17:42:06 +0100 Subject: [PATCH] Fix pagination in query() --- src/QueryBuilder.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 9639964..afb5d80 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -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}"; @@ -229,7 +229,6 @@ protected function generateCallback() implode(' : ', $stmt->errorInfo()) ); } - if ('select' !== strtolower(substr($sql, 0, 6))) { return $result; }