summaryrefslogtreecommitdiff
path: root/idiorm.php
diff options
context:
space:
mode:
Diffstat (limited to 'idiorm.php')
-rw-r--r--idiorm.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/idiorm.php b/idiorm.php
index c4b649c..a878286 100644
--- a/idiorm.php
+++ b/idiorm.php
@@ -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);
}