@@ -153,7 +153,7 @@ public function read($id = null) : array
153
153
if ( $ id ) $ this ->{$ this ->key } = $ id ;
154
154
$ sql = "{$ this ->getSelectQuery ()} " ;
155
155
$ sql .= "{$ this ->getWhereQuery (single: true )} " ;
156
- $ sql .= "{$ this ->getLimitQuery (limit: 1 )}; " ;
156
+ $ sql .= "{$ this ->getLimitQuery (1 )}; " ;
157
157
return $ this ->getRow ($ sql );
158
158
}
159
159
@@ -211,7 +211,7 @@ public function delete($id = null) : bool
211
211
if ( $ id ) $ this ->{$ this ->key } = $ id ;
212
212
$ sql = "{$ this ->getDeleteQuery ()} " ;
213
213
$ sql .= "{$ this ->getWhereQuery (single: true )} " ;
214
- $ sql .= "{$ this ->getLimitQuery (limit: 1 )}; " ;
214
+ $ sql .= "{$ this ->getLimitQuery (1 )}; " ;
215
215
return (bool )$ this ->execute ($ sql );
216
216
}
217
217
@@ -271,14 +271,15 @@ public function query(string $sql, ?array $bind = null, ?string $type = null, ?i
271
271
* @param mixed $columns
272
272
* @param array $sort
273
273
* @param int $limit
274
+ * @param ?int $page
274
275
* @return array
275
276
*/
276
- public function search ($ columns = '* ' , array $ sort = [], ? int $ limit = 0 ) : array
277
+ public function search ($ columns = '* ' , array $ sort = [], int $ limit = 0 , ? int $ page = null ) : array
277
278
{
278
279
$ sql = "{$ this ->getSelectQuery ($ columns )} " ;
279
280
$ sql .= "{$ this ->getWhereQuery ()} " ;
280
281
$ sql .= "{$ this ->getSortQuery ($ sort )} " ;
281
- $ sql .= "{$ this ->getLimitQuery ($ limit )}; " ;
282
+ $ sql .= "{$ this ->getLimitQuery ($ limit, $ page )}; " ;
282
283
return (array )$ this ->execute ($ sql );
283
284
}
284
285
@@ -296,7 +297,7 @@ public function searchOne($columns = '*', array $sort = []) : array
296
297
$ sql = "{$ this ->getSelectQuery ($ columns )} " ;
297
298
$ sql .= "{$ this ->getWhereQuery ()} " ;
298
299
$ sql .= "{$ this ->getSortQuery ($ sort )} " ;
299
- $ sql .= "{$ this ->getLimitQuery (limit: 1 )}; " ;
300
+ $ sql .= "{$ this ->getLimitQuery (1 )}; " ;
300
301
return $ this ->getRow ($ sql );
301
302
}
302
303
@@ -308,14 +309,15 @@ public function searchOne($columns = '*', array $sort = []) : array
308
309
* @param string $column
309
310
* @param array $sort
310
311
* @param int $limit
312
+ * @param ?int $page
311
313
* @return array
312
314
*/
313
- public function searchColumn (string $ column , array $ sort = [], ? int $ limit = 0 ) : array
315
+ public function searchColumn (string $ column , array $ sort = [], int $ limit = 0 , ? int $ page = null ) : array
314
316
{
315
317
$ sql = "{$ this ->getSelectQuery ($ column )} " ;
316
318
$ sql .= "{$ this ->getWhereQuery ()} " ;
317
319
$ sql .= "{$ this ->getSortQuery ($ sort )} " ;
318
- $ sql .= "{$ this ->getLimitQuery ($ limit )}; " ;
320
+ $ sql .= "{$ this ->getLimitQuery ($ limit, $ page )}; " ;
319
321
return $ this ->getColumn ($ sql );
320
322
}
321
323
@@ -912,13 +914,21 @@ private function getSortQuery(array $sort = []) : string
912
914
*
913
915
* @access private
914
916
* @param int $limit
917
+ * @param ?int $page
915
918
* @return string
916
919
*/
917
- private function getLimitQuery (? int $ limit = 0 ) : string
920
+ private function getLimitQuery (int $ limit = 0 , ? int $ page = null ) : string
918
921
{
919
922
$ sql = '' ;
920
923
if ( $ limit ) {
921
- $ sql .= "LIMIT {$ limit }" ;
924
+ if ( !$ this ->isType ('null ' , $ page ) ) {
925
+ $ page = $ page ?: 1 ;
926
+ $ offset = ($ page - 1 ) * $ limit ;
927
+ $ sql .= "LIMIT {$ offset }, {$ limit }" ;
928
+
929
+ } else {
930
+ $ sql .= "LIMIT {$ limit }" ;
931
+ }
922
932
}
923
933
return $ sql ;
924
934
}
0 commit comments