@@ -153,7 +153,7 @@ public function read($id = null) : array
153153 if ( $ id ) $ this ->{$ this ->key } = $ id ;
154154 $ sql = "{$ this ->getSelectQuery ()} " ;
155155 $ sql .= "{$ this ->getWhereQuery (single: true )} " ;
156- $ sql .= "{$ this ->getLimitQuery (limit: 1 )}; " ;
156+ $ sql .= "{$ this ->getLimitQuery (1 )}; " ;
157157 return $ this ->getRow ($ sql );
158158 }
159159
@@ -211,7 +211,7 @@ public function delete($id = null) : bool
211211 if ( $ id ) $ this ->{$ this ->key } = $ id ;
212212 $ sql = "{$ this ->getDeleteQuery ()} " ;
213213 $ sql .= "{$ this ->getWhereQuery (single: true )} " ;
214- $ sql .= "{$ this ->getLimitQuery (limit: 1 )}; " ;
214+ $ sql .= "{$ this ->getLimitQuery (1 )}; " ;
215215 return (bool )$ this ->execute ($ sql );
216216 }
217217
@@ -271,14 +271,15 @@ public function query(string $sql, ?array $bind = null, ?string $type = null, ?i
271271 * @param mixed $columns
272272 * @param array $sort
273273 * @param int $limit
274+ * @param ?int $page
274275 * @return array
275276 */
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
277278 {
278279 $ sql = "{$ this ->getSelectQuery ($ columns )} " ;
279280 $ sql .= "{$ this ->getWhereQuery ()} " ;
280281 $ sql .= "{$ this ->getSortQuery ($ sort )} " ;
281- $ sql .= "{$ this ->getLimitQuery ($ limit )}; " ;
282+ $ sql .= "{$ this ->getLimitQuery ($ limit, $ page )}; " ;
282283 return (array )$ this ->execute ($ sql );
283284 }
284285
@@ -296,7 +297,7 @@ public function searchOne($columns = '*', array $sort = []) : array
296297 $ sql = "{$ this ->getSelectQuery ($ columns )} " ;
297298 $ sql .= "{$ this ->getWhereQuery ()} " ;
298299 $ sql .= "{$ this ->getSortQuery ($ sort )} " ;
299- $ sql .= "{$ this ->getLimitQuery (limit: 1 )}; " ;
300+ $ sql .= "{$ this ->getLimitQuery (1 )}; " ;
300301 return $ this ->getRow ($ sql );
301302 }
302303
@@ -308,14 +309,15 @@ public function searchOne($columns = '*', array $sort = []) : array
308309 * @param string $column
309310 * @param array $sort
310311 * @param int $limit
312+ * @param ?int $page
311313 * @return array
312314 */
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
314316 {
315317 $ sql = "{$ this ->getSelectQuery ($ column )} " ;
316318 $ sql .= "{$ this ->getWhereQuery ()} " ;
317319 $ sql .= "{$ this ->getSortQuery ($ sort )} " ;
318- $ sql .= "{$ this ->getLimitQuery ($ limit )}; " ;
320+ $ sql .= "{$ this ->getLimitQuery ($ limit, $ page )}; " ;
319321 return $ this ->getColumn ($ sql );
320322 }
321323
@@ -912,13 +914,21 @@ private function getSortQuery(array $sort = []) : string
912914 *
913915 * @access private
914916 * @param int $limit
917+ * @param ?int $page
915918 * @return string
916919 */
917- private function getLimitQuery (? int $ limit = 0 ) : string
920+ private function getLimitQuery (int $ limit = 0 , ? int $ page = null ) : string
918921 {
919922 $ sql = '' ;
920923 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+ }
922932 }
923933 return $ sql ;
924934 }
0 commit comments