diff options
Diffstat (limited to 'idiorm.php')
-rw-r--r-- | idiorm.php | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -97,6 +97,12 @@ // Array of WHERE clauses private $where = array(); + // LIMIT + private $limit = null; + + // OFFSET + private $offset = null; + // The data for a hydrated instance of the class private $data = array(); @@ -267,6 +273,22 @@ } /** + * Add a LIMIT to the query + */ + public function limit($limit) { + $this->limit = $limit; + return $this; + } + + /** + * Add an OFFSET to the query + */ + public function offset($offset) { + $this->offset = $offset; + return $this; + } + + /** * Build a SELECT statement based on the clauses that have * been passed to this instance by chaining method calls. */ @@ -295,6 +317,18 @@ } } + // Add LIMIT if present + if (!is_null($this->limit)) { + $query[] = "LIMIT ?"; + $this->values[] = $this->limit; + } + + // Add OFFSET if present + if (!is_null($this->offset)) { + $query[] = "OFFSET ?"; + $this->values[] = $this->offset; + } + return join(" ", $query); } |