From ddcd8a2961f177529281e9a10cf70f73147fd68b Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Thu, 17 Jul 2025 11:09:02 +0200 Subject: [PATCH] fix: `$offset` not set when passing integer to `$limit` in `limit()` (#50) This PR just sets the `OFFSET` value to `0` if no offset is provided for all calls to `limit()`. This fixes a bug where no `OFFSET` was set if the `$limit` parameter was given an integer.. which was the only allowed type except null anyways. Reviewed-on: https://codeberg.org/vlw/php-mysql/pulls/50 --- src/MySQL.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/MySQL.php b/src/MySQL.php index 074df8c..1dff427 100644 --- a/src/MySQL.php +++ b/src/MySQL.php @@ -163,17 +163,8 @@ return $this; } - // Set LIMIT without range directly as integer - if (is_int($limit)) { - $this->limit = $limit; - return $this; - } - - // No offset defined, set limit property directly as string - if (is_null($offset)) { - $this->limit = (string) $limit; - return $this; - } + // Coerce offset to zero if no offset is defined + $offset = $offset ?? 0; // Set limit and offset as SQL CSV $this->limit = "{$offset},{$limit}";