diff --git a/src/MySQL.php b/src/MySQL.php index cd4964b..ad1e425 100644 --- a/src/MySQL.php +++ b/src/MySQL.php @@ -17,7 +17,7 @@ private ?string $order_by = null; private ?string $filter_sql = null; private array $filter_values = []; - private int|string|null $limit = null; + private ?string $limit = null; // Pass constructor arguments to driver function __construct() { @@ -151,25 +151,20 @@ } // Return SQL LIMIT string from integer or array of [offset => limit] - public function limit(int|array|null $limit): self { + public function limit(?int $limit, ?int $offset = null): self { // Unset row limit if null was passed if ($limit === null) { $this->limit = null; return $this; } - // Set LIMIT without range directly as integer - if (is_int($limit)) { - $this->limit = $limit; + // No offset defined, set limit property directly as string + if (is_null($offset)) { + $this->limit = (string) $limit; return $this; } - // Use array key as LIMIT range start value - $offset = (int) array_keys($limit)[0]; - // Use array value as LIMIT range end value - $limit = (int) array_values($limit)[0]; - - // Set limit as SQL CSV + // Set limit and offset as SQL CSV $this->limit = "{$offset},{$limit}"; return $this; }